Skip to content

Instantly share code, notes, and snippets.

@HootsuiteJosh
Created March 28, 2018 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HootsuiteJosh/eb242a21bdfd639926f6f8bce84d024b to your computer and use it in GitHub Desktop.
Save HootsuiteJosh/eb242a21bdfd639926f6f8bce84d024b to your computer and use it in GitHub Desktop.
<?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