I really tried to import contacts in real time. But after a few days, R & DI discovered https://dev.office.com/blogs/outlook-rest-api-v1-0-office-365-discovery-and-live-connect-api-deprecation , which made me switch to microsoft chart. I also tried other things with the azure documentation, but I found it very confusing, but still I was not clear with this. So I implemented the following in php, which turned out to be successful. Just follow these steps: 1) Create your application at https://apps.dev.microsoft.com a) Create a new password. Save the application ID and password using you. b) Add the platform as a web page and add the redirect URL using https, since only https can be used, and http is not used. c) Check the Live SDK support in the "Advance Options" section and save.
2) pass the scope in the contacts.read url as we need signed in user contacts.
$client_id="YOUR_CLIENT_ID"; $redirect_uri = SiteUrl.'hotmail-contact'; $url="https://login.microsoftonline.com/common/oauth2/v2.0/authorize? client_id=".$client_id." &response_type=code &redirect_uri=".$redirect_uri." &response_mode=query &scope=offline_access%20user.read%20mail.read%20contacts.read &state=12345";
3) After successful authentication, it will return the auth code. Now, having received the code, we will receive the request for the token using the curl post request at https://login.live.com/oauth20_token.srf with postfields as
$fields=array( 'code'=> urlencode($auth_code), 'client_id'=> urlencode($client_id), 'client_secret'=> urlencode($client_secret), 'redirect_uri'=> urlencode($redirect_uri), 'grant_type'=> urlencode('authorization_code') );
4) To get contacts
$ url = ' https://graph.microsoft.com/v1.0/me/contacts ' we can even apply filters to them
Now request curl with url and token parameters
public function curl_use_token($url,$token) { $ch = curl_init(); curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); // curl_setopt($ch,CURLOPT_HTTPHEADER,array('HeaderName: HeaderValue')); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization:Bearer '.$token)); // curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization", "Bearer " + $token)); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); $data = curl_exec($ch); curl_close($ch); // print(gettype($data)); // print($data); return $data; }
5) After receiving the data, the returned data will not be in pure json format, so we can extract only part of json from the data using regex, and after decoding it, we can use it. thank you for reading