我从http://nocturnsoft.com/devblog/?p=174网站获得了以下代码,一切正常。但遇到一个小的UI问题。登录窗口未在弹出窗口中打开。我想包括js sdk或只是使用不同的代码。弹出窗口是关键部分,因为我将使用in和iFrame调用页面。
提前致谢。
require_once "src/facebook.php";
$app_id = "xxx";
$app_secret = "xxx";
// Init facebook api.
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
// Get the url to redirect for login to facebook
// and request permission to write on the user's wall.
$login_url = $facebook->getLoginUrl(
array('scope' => 'publish_stream')
);
// If not authenticated, redirect to the facebook login dialog.
// The $login_url will take care of redirecting back to us
// after successful login.
if (! $facebook->getUser()) {
echo <<< EOT
<script type="text/javascript">
top.location.href = "$login_url";
</script>;
EOT;
exit;
}
// Do the wall post.
$facebook->api("/me/feed", "post", array(
message => "Testing Wall post",
picture => "http://www.cjp.org/display_image.aspx?ID=348063",
link => "http://www.cjp.org",
name => "Combined Jewish Philanthropies",
caption => "The Jewish Federations of North America"
));
答案 0 :(得分:0)
您使用的方法仅将用户重定向到应用程序登录页面。如果你想要一个弹出窗口,你应该使用JS SDK和FB.login函数,如下所述:
https://developers.facebook.com/docs/reference/javascript/FB.login/