PHP code example of ramsey / laravel-oauth2-instagram

1. Go to this page and download the library: Download ramsey/laravel-oauth2-instagram library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ramsey / laravel-oauth2-instagram example snippets

 php
Ramsey\Laravel\OAuth2\Instagram\InstagramServiceProvider::class
 php
'Instagram' => Ramsey\Laravel\OAuth2\Instagram\Facades\Instagram::class
 bash
php artisan vendor:publish
 php
$authUrl = Instagram::authorize([], function ($url, $provider) use ($request) {
    $request->session()->put('instagramState', $provider->getState());
    return $url;
});

return redirect()->away($authUrl);
 php
if (!$request->has('state') || $request->state !== $request->session()->get('instagramState')) {
    abort(400, 'Invalid state');
}

if (!$request->has('code')) {
    abort(400, 'Authorization code not available');
}

$token = Instagram::getAccessToken('authorization_code', [
    'code' => $request->code,
]);

$request->session()->put('instagramToken', $token);
 php
$instagramToken = $request->session()->get('instagramToken');

$instagramUser = Instagram::getResourceOwner($instagramToken);
$name = $instagramUser->getName();
$bio = $instagramUser->getDescription();

$feedRequest = Instagram::getAuthenticatedRequest(
    'GET',
    'https://api.instagram.com/v1/users/self/feed',
    $instagramToken
);

$client = new \GuzzleHttp\Client();
$feedResponse = $client->send($feedRequest);
$instagramFeed = json_decode($feedResponse->getBody()->getContents());