使用 PHP sdk 进行应用程序授权
我正在使用 最新 Facebook PHP SDK 并且想要简单地访问用户数据:
$facebook = new Facebook(array(
'appId' => 'xxx',
'secret' => 'yyy',
'cookie' => true
));
$user = $facebook->getUser();
if ($user) { // Checks if there is already a logged in user
try {
// Proceed knowing you have a logged in user who's already authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
else {
//Ask for bare minimum login
$login_url = $facebook->getLoginUrl();
header("Location: ".$login_url);
}
我的问题是$user
已登录 FB,但 $facebook->api('/me')
不仅失败,而且我没有收到应用程序授权对话框任何一个。 我做错了什么?
I'm using the latest Facebook PHP SDK and want to simply access user data:
$facebook = new Facebook(array(
'appId' => 'xxx',
'secret' => 'yyy',
'cookie' => true
));
$user = $facebook->getUser();
if ($user) { // Checks if there is already a logged in user
try {
// Proceed knowing you have a logged in user who's already authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
else {
//Ask for bare minimum login
$login_url = $facebook->getLoginUrl();
header("Location: ".$login_url);
}
My problem is that the $user
is FB logged in, but $facebook->api('/me')
not only fails, but I don't get the App authorization dialog either.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最终发现我的错误,所以记录一下:
Eventually found my error so for the record:
尝试以下 FB 演示脚本:https://github。 com/facebook/facebook-php-sdk/blob/master/examples/example.php
看看是否有效
Try the FB demo script at : https://github.com/facebook/facebook-php-sdk/blob/master/examples/example.php
See if that works