<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yusefauto1 / guzzle-oauth2-plugin-compat example snippets
use Guzzle\Http\Client;
use CommerceGuys\Guzzle\Plugin\Oauth2\Oauth2Plugin;
$accessToken = array(
'access_token' => 'e72758a43e1646969f9f7bd7737d0cd637ed17ae',
'expires' => '1391617481', // Optional.
);
$oauth2Plugin = new Oauth2Plugin();
$oauth2Plugin->setAccessToken($accessToken);
$client = new Client('https://mysite.com/api');
$client->addSubscriber($oauth2Plugin);
$request = $client->get('me');
use Guzzle\Http\Client;
use CommerceGuys\Guzzle\Plugin\Oauth2\Oauth2Plugin;
use CommerceGuys\Guzzle\Plugin\Oauth2\GrantType\PasswordCredentials;
use CommerceGuys\Guzzle\Plugin\Oauth2\GrantType\RefreshToken;
$oauth2Client = new Client('https://mysite.com/oauth2/token');
$config = array(
'username' => 'myusername',
'password' => 'mypassword',
'client_id' => 'myclient',
'client_secret' => 'mysecret',
'scope' => 'administration', // Optional.
);
$grantType = new PasswordCredentials($oauth2Client, $config);
$refreshTokenGrantType = new RefreshToken($oauth2Client, $config);
$oauth2Plugin = new Oauth2Plugin($grantType, $refreshTokenGrantType);
$client = new Client('https://mysite.com/api');
$client->addSubscriber($oauth2Plugin);
$request = $client->get('me');
// $oauth2Plugin->getAccessToken() and $oauth2Plugin->getRefreshToken() can be
// used to export the tokens so that they can be persisted for next time.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.