我正在尝试使用应用中心推广我的应用,但从 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/