Facebook使用PHP SDK进行身份验证

时间:2013-07-21 13:50:25

标签: facebook facebook-graph-api authentication

我正在尝试使用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.我哪里错了?

0 个答案:

没有答案