Created
May 29, 2017 10:37
-
-
Save angarsky/9f43e9fcccfc7fbb3a8242fedc6fe03e to your computer and use it in GitHub Desktop.
Example of code to make an API call with Access Token
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
$client_id = ''; | |
$client_secret = ''; | |
$endpoint = "http://site.dev"; | |
if (!isset($_GET['access_token'])) { | |
print 'Access token is not define.'; | |
die; | |
} | |
$curl = curl_init($endpoint . '/api/sso/v0.1/user/profile'); | |
$data = '{"username":"my@mail.dev"}'; | |
curl_setopt($curl, CURLOPT_POST, true); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl, CURLOPT_HTTPHEADER, array( | |
'Content-Type: application/json', | |
'Content-Length: ' . strlen($data), | |
'Authorization: Bearer ' . $_GET['access_token'] | |
) | |
); | |
try { | |
$output = curl_exec($curl); | |
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE); | |
} catch (Exception $e) { | |
$output = $e->getMessage(); | |
} | |
curl_close($curl); | |
echo $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment