使用curl连接到https://oauth.live.com/authorize

时间:2012-02-23 10:49:50

标签: php curl windows-live

我正在尝试使用php获取Windows实时连接。我用ws获得js sdk但不是用PHP。 这是我的代码:

$CLIENT_ID =variable_get('example_contact_grabber_hotmail_client_id',NULL);
$REDIRECT_URL = variable_get('example_contact_grabber_hotmail_url_callback',NULL);
//dpm($REDIRECT_URL);
$url = "https://oauth.live.com/authorize?client_id=$CLIENT_ID&scope=wl.signin&response_type=code&redirect_uri=$REDIRECT_URL";
$url = str_replace( "&", "&", urldecode(trim($url)) );
//dpm($url);
$ch = curl_init($url);
curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, TRUE); 
  $salida = curl_exec($ch);
  curl_close($ch);
  $todo = split("\n",$salida);

//dpm($todo);

请求给我这条消息。

Array
(
    [0] => <html><head><title>Object moved</title></head><body>
    [1] => <h2>Object moved to <a href="https://login.live.com/login.srf?wa=wsignin1.0&amp;rpsnv=11&amp;checkda=1&amp;ct=1329999219&amp;rver=6.1.6208.0&amp;wp=MBI_SSL&amp;wreply=https:%2F%2Foauth.live.com%2Fauthorize%3Fclient_id%3D000000004008DFE4%26scope%3Dwl.signin%26response_type%3Dcode%26redirect_uri%3Dhttp:%2F%2Fpruebas.eneomed.es%2Flivesdk%2FSamples%2FPHP%2FOauthSample%2Fcallback.php%26auth_redirect%3Dtrue&amp;lc=1033&amp;id=276649&amp;popupui=1">here</a>.</h2>
    [2] => </body></html>
    [3] => 
)

如果我在Firefox中查看$url,那就没事了。

1 个答案:

答案 0 :(得分:0)

尝试添加:


curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//And change
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  //true to false

希望有所帮助