![](/img/trans.png)
[英]Facebook redirects to canvas url instead of the app on facebook
[英]Logging into Facebook App redirects to canvas URL
所以我開始學習Facebook應用程序,並得到了我的第一個障礙。 每當我登錄到我的簡單hello用戶應用程序時,我都會被重定向到畫布URL(應用程序內容直接在服務器上打開,而不是在facebook iFrame中打開)。
這是代碼
<?php
require_once("php-sdk/facebook.php");
$config = array(
'appId' => '',
'secret' => ''
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
$params = array(
'scope' => 'read_stream, friends_likes',
'redirect_uri' => 'https://apps.facebook.com/401822713222945/'
);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<?php
if ($user_id){
try {
$user_profile = $facebook->api('/me','GET');
echo 'Welcome ' . $user_profile['name'] . '!';
} catch(FacebookApiException $e) {
$login_url = $facebook->getLoginUrl();
echo 'Please <a href="' . $login_url . '" onclick="top.location.href = \'' . $login_url . '\'">log in.</a>';
error_log($e->getType());
error_log($e->getMessage());
}
} else {
$login_url = $facebook->getLoginUrl();
echo 'Please <a href="' . $login_url . '" onclick="top.location.href = \'' . $login_url . '\'">log in.</a>';
}
?>
</body>
</html>
在<body>
標記后面嘗試以下操作。
<script type="text/javascript">
if(top === self){
document.location = "<?php echo $params['redirect_uri'];?>";
}
</script>
它將檢查當前窗口是否是最頂層窗口,如果您直接訪問該頁面,它將重定向到iframed頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.