vlucas / openx-oauth-client
Modern PHP client for working with the OpenX v4 oAuth API
Requires
- guzzlehttp/guzzle: ~4.0
- guzzlehttp/oauth-subscriber: ~0.1
Requires (Dev)
- vlucas/phpdotenv: ~1.0
This package is auto-updated.
Last update: 2024-12-08 12:34:56 UTC
README
Uses Guzzle v4.x and the oauth-subscriber plugin.
Installation
php composer.phar require vlucas/openx-oauth-client
Usage in your code:
// Setup client and login with user $client = new Vlucas\OpenX($consumerKey, $consumerSecret, $oauthRealm, 'http://ox-ui.example.com/ox/4.0/'); $client->login('user@example.com', 'souper-seekret-password'); // GET /account - for list of accounts $res = $client->get('account'); var_dump($res->json());
You should see the JSON dumped out for the accounts endpoint. Feel free to make any other requests you want.
Be sure to read the OpenX API v4 Documentation!
Making HTTP Requests
The OpenX client proxies all normal get/post/put/delete, etc. requests through
and automatically adds the required Cookie
header before sending the request.
// Makes normal request with necessary Cookie header $res = $client->get('account');
Access to the Guzzle Client
If you need to get the base Guzzle object to make any further requests or modifications, you can:
// Returns the main GuzzleHttp\Client object $guzzle = $client->getClient();
Please note that if you do this, the required Cookie
header will not be
attached to your requests automatically, so you will need to do this yourself
with $client->getAuthCookie()
.
Using the Example
Steps to run the provided example.php:
composer install --dev
cp .env.example .env
- Edit
.env
to add oAuth consumer key and secret, user/pass, etc. - Run it:
php example.php