我正在尝试将我的 Web 应用程序与 Facebook 平台集成。
下面是我的测试代码,
if ($_REQUEST['error_reason']) { echo("<script> top.location.href='http://facebook.com'</script>"); }
else {
$app_id = "APP_CODE";
$canvas_page = "https://e3xcp.com/hs/fb/";
$auth_url = "http://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($canvas_page) "&scope=email,user_birthday,user_hometown,user_location,user_religion_politics,user_website,user_checkins";
$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 {
echo ("Welcome User: " . $data["user_id"] . "<BR><BR>");
print_r($data);
echo "<BR><BR>". $data['oauth_token'] . "<BR><BR>";
$graph_url = "https://graph.facebook.com/me?access_token=". trim($data['oauth_token']);
$json_data = file_get_contents($graph_url);
$me = json_decode($json_data);
echo $me->id;
}
}
有两个问题,
在进行身份验证(新用户)时,当用户按下“允许”按钮时,浏览器会在我的画布页面和 facebook 服务器之间来回导航。
当经过身份验证的用户访问该应用程序时,我收到一条错误消息,
**> Warning: file_get_contents(https://graph.facebook.com/me?access_token=200335043341031|2.axhed5PlPjICLqIN2ElgGA__.3600.1304254800.1-100001278552830|ez-LK5f_ymd-q9Ju4qa7zAvjEgo) [function.file-get-contents]: failed to open stream: No error in C:\Inetpub\vhosts\E3XCP.COM\httpdocs\hs\FB\index.php on line 19**
但是当我复制并粘贴 GRAPH URL
***https://graph.facebook.com/me?access_token=200335043341031|2.axhed5PlPjICLqIN2ElgGA__.3600.1304254800.1-100001278552830|ez-LK5f_ymd-q9Ju4qa7zAvjEgo*** it returns the correct output
Facebook Developers 文档中提供了两个身份验证示例,我尝试了这两种方法。
该应用程序链接是http://apps.facebook.com/slhoroscope Help !!!