Skip to content

Import contacts from Outlook, Office 365 and Live to your PHP application

Last updated on June 4, 2019

In this tutorial I will show you, how to import Outlook,office 365 and Live contacts to your web project, using a PHP.

Microsoft Apps Creation

To access Microsoft APIs you need to create Microsoft App and specify App ID & App Secret at the time of calling Microsoft APIs. It take only few seconds for registering your application with MSN. Go following link to create app with your desired name- https://account.live.com/developers/applications/create

Now create a url in the following format

 Get contacts

My redirect url is https://arjunphp.com/outlook-contactss.php, so lets create it with below code.

'authorization_code',
      'code'=> $_GET['code'],
      'redirect_uri'=>'https://arjunphp.com/outlook-contactss.php',
      'client_id'=> 'your_client_id',
      'client_secret'=> 'your_client_secret'
    )));
 
// 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);
0 0 votes
Article Rating
Subscribe
Notify of
guest

12 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments