Created
February 19, 2018 20:04
-
-
Save jonathansanchez/d05e1e1c35ac67c757d713781405aad6 to your computer and use it in GitHub Desktop.
Example: html button to get contacts from Outlook/Live/Hotmail in Graph Outlook
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 | |
// initiate cURL resource | |
$ch = curl_init(); | |
// where you want to post data | |
$url = "https://login.microsoftonline.com/common/oauth2/v2.0/token"; | |
curl_setopt($ch, CURLOPT_URL,$url); | |
// tell curl you want to post something | |
curl_setopt($ch, CURLOPT_POST, true); | |
// define what you want to post | |
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array( | |
'grant_type'=>'authorization_code', | |
'code'=> $_GET['code'], | |
'redirect_uri'=>'https://www.example.com/callbak.php', | |
'client_id'=> 'YOUR_CLIENT_ID', //https://account.live.com/developers/applications/create | |
'client_secret'=> 'YOUR_SECRET_PASS' | |
))); | |
// return the output in string format | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
// execute post | |
$output = curl_exec ($ch); | |
// close the connection | |
curl_close ($ch); | |
// show output | |
$info = json_decode($output); | |
$curl_h = curl_init('https://graph.microsoft.com/v1.0/me/contacts'); | |
curl_setopt($curl_h, CURLOPT_HTTPHEADER, | |
array( | |
"Authorization: Bearer $info->access_token", | |
) | |
); | |
# do not output, but store to variable | |
curl_setopt($curl_h, CURLOPT_RETURNTRANSFER, true); | |
$response = curl_exec($curl_h); | |
print_r($response); |
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
<a href="https://login.microsoftonline.com/common/oauth2/v2.0/authorize? | |
state=some_random_string | |
&scope=https%3A%2F%2Fgraph.microsoft.com%2Fcontacts.read | |
&response_type=code&approval_prompt=auto | |
&client_id=YOUR_CLIENT_ID | |
&redirect_uri=https%3A%2F%2Fwww.example.com%2Fcallbak.php">Get contacts</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment