我正在尝试将我的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开发者文档中给出了两个认证示例,我尝试了这两种方法。
应用链接为http://apps.facebook.com/slhoroscope帮助! !
- 你需要使用画布页面而不是画布Url,即
- 这与你的PHP配置有关,很可能是openssl扩展。
$canvas_page = "http://apps.facebook.com/slhoroscope/";