PHP code example of hannesvdvreken / php-oauth

1. Go to this page and download the library: Download hannesvdvreken/php-oauth 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/ */

    

hannesvdvreken / php-oauth example snippets


$service = new OAuth\Services\Github();

$redirectUri = 'https://example.com/oauth/callback';

$credentials = array(
    'client_id'     => 'client-id',
    'client_secret' => '****',
);

$scopes = array('user', 'user:email');

$token = array(
    'access_token' => $accessToken;
);

$service = new OAuth\Services\Github($redirectUri, $credentials, $scopes, $token);

$service = new OAuth\Services\Github;
$service
    ->setRedirectUri($redirectUri)
    ->setCredentials($credentials)
    ->setScopes($scopes)
    ->setToken($token);

$redirectUri = $service->getRedirectUri();
$credentials = $service->getCredentials();
$scopes      = $service->getScopes();
$token       = $service->getToken();

$service->setClient(new GuzzleHttp\Client);
$service->getClient();

$response = $service->get('users/self')->json();

$body = ['status' => 'Tweeted with @hannesvdvreken/php-oauth'];
$status = $twitter->post('statuses/update', compact('body'))->json();

$twitter = OAuth::consumer('twitter');

$twitter = new OAuth\Services\Twitter($redirectUri, $credentials);

// Request token for redirecting the user (store it in session afterwards).
$token = $twitter->requestToken();

// Get the url to which we need to redirect the user.
$url = $twitter->authorizationUrl();

// Redirect the user.
header('Location: '. $url); exit;

// Get the url to which we need to redirect the user.
$url = $twitter->authorizationUrl();

// Get the requestToken that has been requested.
$token = $twitter->getToken();
// And store it.

// And redirect the user.
header('Location: '. $url); exit;

// Give the stored token back to the service class.
$twitter->setToken($token);

// Exchange the get parameters for an access token.
$token = $twitter->accessToken($oauthToken, $oauthVerifier);

// Do a get request, just like you would do with a Guzzle Client.
$profile = $twitter->get('account/verify_credentials.json')->json();

$fb = new OAuth\Services\Facebook();

$url = $fb->authorizationUrl();

header('Location: '. $url);

$fb->accessToken($code);

$profile = $fb->get('me')->json();
bash
php artisan config:publish hannesvdvreken/php-oauth