Created
March 28, 2018 23:40
-
-
Save HootsuiteJosh/eb242a21bdfd639926f6f8bce84d024b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'vendor/autoload.php'; | |
use GuzzleHttp\Client; | |
const HOOTSUITE_CLIENT_ID = 'yourclientid'; // your client ID and secret are available through the developer dash | |
const HOOTSUITE_CLIENT_SECRET = 'yourclientsecret'; // if you don't have API access yet, email app.directory@hootsuite.com | |
$member_id = '17107276'; // the memberId of a user of your Hootsuite app, available through the dashboard SDK | |
$client = new Client([ | |
'base_uri' => 'https://platform.hootsuite.com' | |
]); | |
try { | |
$response = $client->post('/auth/oauth/v2/token', [ | |
'form_params' => [ | |
'grant_type' => 'member_app', | |
'member_id' => $member_id | |
], | |
'headers' => [ | |
'Authorization' => 'Basic ' . base64_encode(HOOTSUITE_CLIENT_ID . ':' . HOOTSUITE_CLIENT_SECRET) | |
] | |
] | |
); | |
} catch (GuzzleHttp\Exception\ClientException $e) { | |
// ... | |
} | |
$token = json_decode($response->getBody())->access_token; | |
try { | |
$response = $client->get('/v1/me', [ | |
'headers' => [ | |
'Authorization' => 'Bearer ' . $token | |
] | |
] | |
); | |
} catch (GuzzleHttp\Exception\ClientException $e) { | |
// ... | |
} | |
$userDetails = (string) $response->getBody(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment