php-sdk 3.1.1 无法获取测试用户的 $facebook->api('/me') 并且没有显示授权请求
当我使用以下代码时, $user_profile = $facebook->api('/me');将为我(管理员用户)显示信息,但是当我切换到测试用户时,权限对话框永远不会显示测试用户添加应用程序,并且 $user_profile 不会被定义。
我似乎找不到一个代码示例,该代码似乎可以正确执行所有操作,以确保应用程序获得授权并且用户经过身份验证。我从旧的 FB 开发者论坛看到很多人似乎对新程序有同样的问题。
这是代码:
<?php
$appId = "myid";
$secret = "mysecret";
$canvasurl = "http://www.example.com/myappname/";
$canvas = "http://apps.facebook.com/myappname/";
$scope = "user_website,email,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown,manage_pages,offline_access";
require_once "facebook.php";
$facebook = new facebook(array(
'appId' => $appId,
'secret' => $secret
)
);
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
}
catch (FacebookApiException $e) {
$user = null;
}
if (!$user) {
$loginUrl = $facebook->getLoginUrl(
array(
'scope' => $scope,
'redirect_uri' => $canvas
)
);
echo <<<LU
<script type="text/javascript">
top.location.href = $loginUrl;
</script>
LU;
}
}
print_r($user_profile);
?>
谢谢。
When I use the following code, $user_profile = $facebook->api('/me'); will show the info for me, the admin user, but when I switch to a test user the permissions dialog never displays for the test user to add the app and $user_profile doesn't get defined.
I can't seem to find one example of code that seems to do everything properly in terms of making sure the app is authorized and the user is authenticated. I see from the old FB developer forums that a lot of people seem to be having the same issue with the newer procedures.
Here's the code:
<?php
$appId = "myid";
$secret = "mysecret";
$canvasurl = "http://www.example.com/myappname/";
$canvas = "http://apps.facebook.com/myappname/";
$scope = "user_website,email,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown,manage_pages,offline_access";
require_once "facebook.php";
$facebook = new facebook(array(
'appId' => $appId,
'secret' => $secret
)
);
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
}
catch (FacebookApiException $e) {
$user = null;
}
if (!$user) {
$loginUrl = $facebook->getLoginUrl(
array(
'scope' => $scope,
'redirect_uri' => $canvas
)
);
echo <<<LU
<script type="text/javascript">
top.location.href = $loginUrl;
</script>
LU;
}
}
print_r($user_profile);
?>
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将发布我的代码
I will post my code