php-sdk 3.1.1 无法获取测试用户的 $facebook->api('/me') 并且没有显示授权请求

发布于 2024-12-03 09:09:56 字数 1090 浏览 1 评论 0原文

当我使用以下代码时, $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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鱼忆七猫命九 2024-12-10 09:09:56

我将发布我的代码

<?php
    $fbconfig['appid' ] = "";
    $fbconfig['secret'] = "";

    $fbconfig['baseUrl']    =   "";
    $fbconfig['appBaseUrl'] =   "";

    $user            =   null;

    try{
      include_once "src/facebook.php";
    }
    catch(Exception $o){
      echo '<pre>';
      print_r($o);
      echo '</pre>';
    }


    $facebook = new Facebook(array(
       'appId'  => $fbconfig['appid'],
       'secret' => $fbconfig['secret'],
       'cookie' => true,
    ));

    //Facebook Authentication part

    $user       = $facebook->getUser();

    $loginUrl   = $facebook->getLoginUrl(
        array(
            'canvas'    => 1,
            'fbconnect' => 0,
            'scope'         => 'user_status,publish_stream,user_photos'
        )
    );

    if ($user) {
      try {

        $user_profile = $facebook->api('/me');

      } catch (FacebookApiException $e) {
        $user = null;
      }
    }

    if (!$user) {
         echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
         exit;
    }
?>

I will post my code

<?php
    $fbconfig['appid' ] = "";
    $fbconfig['secret'] = "";

    $fbconfig['baseUrl']    =   "";
    $fbconfig['appBaseUrl'] =   "";

    $user            =   null;

    try{
      include_once "src/facebook.php";
    }
    catch(Exception $o){
      echo '<pre>';
      print_r($o);
      echo '</pre>';
    }


    $facebook = new Facebook(array(
       'appId'  => $fbconfig['appid'],
       'secret' => $fbconfig['secret'],
       'cookie' => true,
    ));

    //Facebook Authentication part

    $user       = $facebook->getUser();

    $loginUrl   = $facebook->getLoginUrl(
        array(
            'canvas'    => 1,
            'fbconnect' => 0,
            'scope'         => 'user_status,publish_stream,user_photos'
        )
    );

    if ($user) {
      try {

        $user_profile = $facebook->api('/me');

      } catch (FacebookApiException $e) {
        $user = null;
      }
    }

    if (!$user) {
         echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
         exit;
    }
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文