我正在尝试使用 PHP SDK 进行授权。
$facebook = new Facebook(array(
'appId' => 'xxx',
'secret' => 'xxx',
));
$user = $facebook->getUser();
if($user) {
$user_profile = $facebook->api('/me');
}
<a href="#" onClick='myWin=window.open("<?php echo $facebook->getLoginUrl(array('redirect_uri'=>home_url().'/auth.php')); ?>", "", "width=500,height=400");'">Facebook</a>
这段代码应该授权我并获得个人资料。Redirect_url 脚本看起来像这样
echo "<html><head><meta charset='utf-8'/></head><body><script>
var form=window.opener.document.createElement(\"form\");
form.id = \"red\"
form.action='';
form.method=\"post\";
form.target=\"_top\";
form.style.display=\"none\";
var input=document.createElement(\"input\");
input.type=\"hidden\";
input.name=\"fb_auth\";
input.value='';form.appendChild(input);
window.opener.document.body.appendChild(form);
form.submit();
window.close();
</script></body></html>";
所以$user
总是0。我错在哪里?