Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php curl没有返回任何hotmail联系人_Php_Curl_Contacts_Hotmail - Fatal编程技术网

Php curl没有返回任何hotmail联系人

Php curl没有返回任何hotmail联系人,php,curl,contacts,hotmail,Php,Curl,Contacts,Hotmail,我正在尝试从Hotmail获取联系人。我制作了一个脚本,以前很管用,但现在不再管用了。它确实返回accesstoken,但没有xml或json响应。我确信我有正确的客户id和密码。我正在使用Google App Engine,即使在Google App Engine启动器的日志中也没有出现错误,我浏览器中的控制台本身也是空的 这是我注册应用程序以获取客户端id和密码的地方: Hotmail开发页面: oauth-hotmail.php: <?php //function for par

我正在尝试从Hotmail获取联系人。我制作了一个脚本,以前很管用,但现在不再管用了。它确实返回accesstoken,但没有xml或json响应。我确信我有正确的客户id和密码。我正在使用Google App Engine,即使在Google App Engine启动器的日志中也没有出现错误,我浏览器中的控制台本身也是空的

这是我注册应用程序以获取客户端id和密码的地方:

Hotmail开发页面:

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>
php.ini:


您这边没有系统错误,但login.live.com肯定报告了某种类型的错误,没有?没有。。。没有错误,我还检查了Linkedin以查看live api是否脱机,但它仍然在那里和其他许多地方工作。您从响应中得到了什么?只是
string(0)”
?我试图通过回显$xmlresponse来返回它,但它没有返回任何东西尝试
var\u dump
而不是
echo
。没有系统错误,但是login.live.com肯定报告了某种类型的错误,没有?没有。。。没有错误,我还检查了Linkedin以查看live api是否脱机,但它仍然在那里和其他许多地方工作。您从响应中得到了什么?只是
string(0)”“
?我试图通过回显$xmlresponse来返回它,但它没有返回任何东西尝试
var\u dump
而不是
echo
application: famous-archway-127123
version: 1
runtime: php55
api_version: 1

handlers:
- url: /.*
  script: oauth-hotmail.php
extension=php_curl.dll