Skip to content

Instantly share code, notes, and snippets.

@chx
Last active September 11, 2016 17:52
Show Gist options
  • Save chx/78811d10b6186420ce36432aa98601ff to your computer and use it in GitHub Desktop.
Save chx/78811d10b6186420ce36432aa98601ff to your computer and use it in GitHub Desktop.
list($access_token, $refresh_token, $expires) = $this->getTokens();
$handler_stack = HandlerStack::create();
$client = new Client([
'auth' => 'oauth2',
'handler' => $handler_stack,
'base_uri' => 'https://api.smartsheet.com',
]);
if ($expires < time()) {
$form_params = [
'grant_type' => 'refresh_token',
AuthorizationCode::CONFIG_CLIENT_ID => static::CLIENT_ID,
'refresh_token' => $refresh_token,
'hash' => hash('sha256', static::CLIENT_SECRET . '|' . $refresh_token),
];
$response = $client->post(static::TOKEN_URL, ['form_params' => $form_params]);
$tokens = json_decode($response->getBody());
$access_token = $tokens['access_token'];
$this->saveTokens($tokens); // Don't forget to save the tokens into the database.
}
$body = $client->get('/2.0/users/me', ['headers' => ['Authorization' => "Bearer $access_token"]])->getBody();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment