1

我制作了一个为某种原因注册用户的应用程序。该应用程序从他们的 FB 帐户中获取电子邮件、名称。

39: $token_url = "https://graph.facebook.com/oauth/access_token?client_id=".$app_id."&redirect_uri=".urlencode($my_url)."&client_secret=".$secret."&code=".$code;

40: $access_token = file_get_contents($token_url);

41: $graph_url = "https://graph.facebook.com/me?fields=id,name,email&".$access_token;

42:$user = json_decode(file_get_contents($graph_url));

第 40 行和第 42 行出现错误

[function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /home/*********/index.php on line 40
[function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /home/*********/index.php on line 42

但仅在尝试评估用户提供的字段之后,而不是在第一次启动应用程序时。这段代码中是否有任何错误,或者我应该在脚本中的其他地方查看?

4

1 回答 1

0

请查看此文档以了解实现服务器端身份验证的正确方法,特别是第 6 步。

您的代码将接收和解析的响应正文如下所示:

access_token=USER_ACCESS_TOKEN&expires=NUMBER_OF_SECONDS_UNTIL_TOKEN_EXPIRES

您应该提取 access_token 以供使用。

每当您遇到身份验证问题时,第一步应该是access_tokenOpen Graph Debugger中运行,以确保用户和应用程序通过正确的范围与其绑定。

于 2012-12-09T18:39:01.343 回答