获取访问令牌
我尝试使用下面的代码访问访问令牌:
$code=$_REQUEST['code'];
if(empty($code)) {
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&scope=publish_stream,user_photo_video_tags";
echo("<script>top.location.href='" . $dialog_url . "'</script>");
}
$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
它工作正常,但是当用户第二次尝试使用该应用程序时,在尝试授权用户时没有流畅的流程。
所以,我的问题是如何确保在尝试授权用户时流程顺畅?
I have tried accessing the access token using the code below:
$code=$_REQUEST['code'];
if(empty($code)) {
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&scope=publish_stream,user_photo_video_tags";
echo("<script>top.location.href='" . $dialog_url . "'</script>");
}
$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
It works fine but when the user tries to use the application for the second time, there is no smooth flow while trying to authorize the user.
So, my question is how do I make sure that there smooth flow while trying to authorize the users?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了顺利进行用户授权,我建议您使用最新的 Facebook PHP SDK
这是我的一个示例脚本它处理用户授权:
To do user authorization smoothly I recommend you to use the latest Facebook PHP SDK
Here's an example script of mine which handles the user authorization: