oauth - 用户使用 Facebook 应用中心的 "visit web site"按钮时无法获取访问 token

标签 oauth facebook-apps

我正在尝试使用应用中心推广我的应用,但从 Web 预览中我无法访问该网站。
调用的链接是http://www.myappsite.it/?fb_source=appcenter&fb_appcenter=1&code=a_long_string

从 myappsite 的 index.php 我使用这个和平的 php 代码来让用户来自 facebook

$code = $_REQUEST["code"];

if($_REQUEST['state'] == $_SESSION['state'] && !$user && strlen($code) > 0) 
{
$token_url = "https://graph.facebook.com/oauth/access_token?" . 
"client_id=" . $appId . "&redirect_uri=" . urlencode("http://www.myappsite.it/") . 
"&client_secret=" . $secret . "&code=" . $code;

$response = @file_get_contents($token_url);
$params = null;

parse_str($response, $params);

$graph_url = "https://graph.facebook.com/me?access_token=" .     $params['access_token'];

$user = json_decode(file_get_contents($graph_url));
echo("Hello " . $user->name);
}

但是 $params['access_token'] 是空的,因为 $token_url 返回
{
"error": {
    "message": "Error validating verification code.",
    "type": "OAuthException",
    "code": 100
    }
}

如何让用户从应用中心预览网页登录?

最佳答案

来自 Authenticated Referrals文档的一部分(应用中心算作经过身份验证的推荐)

使用查询字符串设置时的特殊考虑:

If you would like to use the server-side authentication flow it is important to make sure you are passing the redirect_uri parameter correctly when exchanging your code for an access token. You should set your redirect_uri parameter to the click-through URL to your site without the code parameter. In most cases the URL will look something like:

http://www.example.com/?fb_source=search&code=CODE_HERE Once you strip the code parameter it will become:

http://www.example.com/?fb_source=search which is the value that should be set in redirect_uri. Please make sure that this logic is dynamic as the query parameters appended to your click-through URL may be subject to change.



使用上面的示例,这意味着您的 redirect_uri参数应该是 http://www.myappsite.it/?fb_source=appcenter&fb_appcenter=1

关于oauth - 用户使用 Facebook 应用中心的 "visit web site"按钮时无法获取访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11053616/

相关文章:

api - 使用 OAuth...我不明白。我应该做些什么?

docker - 尝试使用 docker 启动 keycloak,但它没有启动。操作 ("add") 失败 - 地址 :

c# - OAuth 不记名 token 不起作用

facebook - 外部登录不适用于 MVC 4 web 应用程序中的 facebook

facebook - Facebook 应用程序和选项卡之间有什么区别?

facebook - 将自定义名称、标题、图像、描述添加到新的 Facebook 共享对话框或自定义故事中,而不是从 og meta 中获取它们

c# - Twitter OAuth 无法正确重定向回我的网站

php - 重定向问题 : Twitter API Oauth

facebook - 服务条款和隐私政策 URL 可以本地化吗?

facebook - 从应用范围的用户 ID 获取 Facebook 用户 ID