1

I am trying to get my contacts from Hotmail. I made a script which used to work, but now it doesn't anymore. It does return a accesstoken, but no xml or json response. I am sure that I have the correct client-id and secret. I am using Google App Engine and even in the log of the Google App Engine Launcher no error appears, the console in my browser itself is also empty.

This is where I registered the application to get both the client id and secret: https://account.live.com/developers/applications/index

Hotmail development page: enter image description here

oauth-hotmail.php:

<?php

//function for parsing the curl request
function curl_file_get_contents($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    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);
    return $data;
}
$client_id = '000000004018D847';
$client_secret = 'CfhxxxxxxxxxxxxxxxNPE';
$redirect_uri = 'http://localhost:11080/oauth-hotmail.php';
$auth_code = $_GET["code"];

$urls_ = 'https://login.live.com/oauth20_authorize.srf?client_id='.$client_id.'&scope=wl.signin+wl.basic+wl.emails+wl.contacts_emails+wl.contacts_birthday+wl.contacts_postal_addresses+wl.contacts_phone_numbers
&response_type=code&redirect_uri='.$redirect_uri;

echo '<a href="'.$urls_.'">Contact From MSN</a>';

$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')
);

$post = '';

foreach($fields as $key=>$value) { $post .= $key.'='.$value.'&'; }
$post = rtrim($post,'&');
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,'https://login.live.com/oauth20_token.srf');
curl_setopt($curl,CURLOPT_POST,5);
curl_setopt($curl,CURLOPT_POSTFIELDS,$post);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
$result = curl_exec($curl);
curl_close($curl);
echo $contents ;

$response =  json_decode($result);

$accesstoken = $response->access_token;
//$accesstoken = $_SESSION['accesstoken'] ;//= $_GET['access_token'];
$url = 'https://apis.live.net/v5.0/me/contacts?access_token='.$accesstoken.'&limit='.$max_results;
$xmlresponse =  curl_file_get_contents($url);
$contacts = json_decode($xmlresponse, true);

echo 'xmlresponse = '.$xmlresponse;
$return = array();
foreach($contacts['data'] as $contact)
{
    $exploded = explode(".", $contact['id']);
    $birthday = $contact['birth_day'].'-'.$contact['birth_month'];

    if(!is_null($contact['phones']['personal'])){
        $phoneNumber = $contact['phones']['personal'];
    }elseif(!is_null($contact['phones']['mobile'])){
        $phoneNumber = $contact['phones']['mobile'];
    }elseif(!is_null($contact['phones']['business'])){
        $phoneNumber = $contact['phones']['business'];
    }else{
        $phoneNumber = null;
    }

    $return[] = array (
        'firstname'=>     $contact['first_name'],
        'lastname'=>      $contact['last_name'],
        'email' =>        $contact['emails']['preferred'],
        'phoneNumber' =>  $phoneNumber,
        'city' =>         $contact['addresses']['personal']['city'],
        'street' =>       $contact['addresses']['personal']['street'],
        'country' =>      $contact['addresses']['personal']['region'],
        'birthday' =>     $birthday,
        'id' =>           $exploded[1],
    );
}

$hotmail_contacts = $return;

$hotmail_json = json_encode($return);

echo '<br><br><pre>';
echo $xmlresponse;
echo '</pre><br><br>';

?>

<table border='1' class="table table-striped table-condensed">
    <thead>
    <tr>
        <th>Voornaam </th>
        <th>Achternaam </th>
        <th>Email </th>
        <th>Telefoon </th>
        <th>Stad </th>
        <th>Adres </th>
        <th>Land </th>
        <th>Verjaardag </th>
        <th>ID </th>
    </tr>
    </thead>
    <tbody>
    <?php
    foreach ($hotmail_contacts as $contacts){
        echo'<tr>';
        echo'<td>'. $contacts['firstname']."</td>";
        echo'<td>'. $contacts['lastname']."</td>";
        echo'<td>'. $contacts['email'].'</td>';
        echo'<td>'. $contacts['phoneNumber']."</td>";
        echo'<td>'. $contacts['city'].'</td>';
        echo'<td>'. $contacts['street']."</td>";
        echo'<td>'. $contacts['country'].'</td>';
        echo'<td>'. $contacts['birthday'].'</td>';
        echo'<td>'. $contacts['id'].'</td>';
        echo'</tr>';
    }
    ?>
    </tbody>

</table>

app.yaml:

application: famous-archway-127123
version: 1
runtime: php55
api_version: 1

handlers:
- url: /.*
  script: oauth-hotmail.php

php.ini:

extension=php_curl.dll
Mike Lammers
  • 542
  • 9
  • 27

0 Answers0