Sco*_*ter 8 javascript php permissions facebook login
当用户通过http://apps.facebook.com/myappxxxxx访问我的Facebook应用程序时,我希望它立即显示请求权限fb对话框 - 就像许多其他人一样.
我尝试了各种各样的东西 - 包括使用getLoginUrl的php重定向,使用相同的javascript窗口位置重定向.
问题是它显示了一个很大的facebook图标而不是请求权限.但是,如果您单击该图标,它实际上会转到正确的请求权限页面!
有谁知道如何正确重定向到Facebook权限页面?
我正在使用带有iFrame FB应用程序的PHP api和JavaScript SDK.
我刚才有同样的问题.这是一个小黑客:
if(!$me) {
$url = "https://graph.facebook.com/oauth/authorize?"
."client_id=YOUR_APP_ID&"
."redirect_uri=http://apps.facebook.com/APP_SLUG/&"
."scope=user_photos,publish_stream";
echo "<script language=javascript>window.open('$url', '_parent', '')</script>";
} else {
your code...
}
Run Code Online (Sandbox Code Playgroud)
它在我的代码中看起来如何(有点脏,我有一个截止日期):
require_once 'facebook-php-sdk/src/facebook.php';
$appid = '';
$facebook = new Facebook(array(
'appId' => $appid,
'secret' => '',
'cookie' => true,
));
$session = $facebook->getSession();
$me = null;
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
}
if(!$me) {
// here we redirect for authentication:
// This is the code you should be looking at:
$url = "https://graph.facebook.com/oauth/authorize?"
."client_id=$appid&"
."redirect_uri=http://apps.facebook.com/APP_SLUG/&"
."scope=user_photos,publish_stream";
?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>Göngum til góðs</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<script language=javascript>window.open('<?php echo $url ?>', '_parent', '')</script>
</head>
<body>
Loading...
</body>
</html>
<?php
exit;
} else {
your code ...
}
Run Code Online (Sandbox Code Playgroud)
简单的标题重定向不起作用,因为它只会重定向您的iframe.访问_parent窗口需要Javascript.
请记住,有一个正确的方法来做到这一点(见下面的答案),我不建议这样做.但是嘿,有什么东西漂浮在你的船上......
归档时间: |
|
查看次数: |
15612 次 |
最近记录: |