Facebook用户ID始终为0

时间:2011-11-21 06:09:05

标签: php facebook

我最近改变了webhosts。从那时起,我一直为Facebook用户ID获得0:

<?php 
$app_id = "xxxxxxxx";
$canvas_page = "http://apps.facebook.com/the_rsg/";
$auth_url = "http://www.facebook.com/dialog/oauth?client_id=".$app_id."&redirect_uri=".urlencode($canvas_page);
$signed_request = $_REQUEST["signed_request"];

list($encoded_sig, $payload) = explode('.', $signed_request, 2);

$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

if (empty($data["user_id"])) {
    echo("<script> top.location.href='".$auth_url."'</script>");
}else{
    $pageContent = file_get_contents('http://graph.facebook.com/'.$data["user_id"]);
    $parsedJson  = json_decode($pageContent);
    $user_id = $parsedJson->id;
    $user_name = $parsedJson->name;
    session_start();
    $_SESSION['UserID'] = $user_id;
}
?>

如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

检查错误日志时:

  

PHP警告:file_get_contents(http://graph.facebook.com/xxxxx)[function.file-get-contents]:

     

无法打开流:在第20行的/home/jay/public_html/index.php中找不到合适的包装器

问题出在php.ini文件中。

解决方案是启用allow_url_fopen