php和javascript sdk上获取用户数据不一致

发布于 2024-12-03 00:28:26 字数 1057 浏览 5 评论 0原文

我一直在开发一个结合使用 php sdk 和 javascript sdk 的 Facebook 应用程序。它在 facebook 上的选项卡式 iframe 中运行,并托管在我自己的服务器上。我现在正在使用最新的 php 和 javascript sdk 文件(2011 年 9 月 6 日下午 2:50)。第一个不一致是在获取用户 ID 时 php sdk 中。这是我的代码:

require 'fb_php_sdk/facebook.php';

$facebook = new Facebook(array(
    'appId'  => $app_id,
    'secret' => $app_secret,
    'cookie' => true
));

$user = $facebook->getUser();
if ($user) {
    $permissions_granted = true;
} else {
    $permissions_granted = false;
}

这经常返回“0”作为 facebook ID,不知道为什么。尽管几乎同样频繁地返回实际的 Facebook ID。

另一个问题是图像。调用此 url 时,我经常得到图像不显示的情况:

<img src="https://graph.facebook.com/' . $uid. '/picture/" />

当我使用 fql 时,执行此查询时,结果不一致地得到“未定义”:

FB.api(
    {
        method: 'fql.query',
        query: 'SELECT name,pic FROM user WHERE uid=<? echo $user ?>'
    },
        function(response)
        {
            alert(response[0].pic);
        }
);

我真的不明白什么会导致这种不一致,这使得错误测试变得非常困难。如果有人经历过这种行为并能指出我正确的方向,我将非常感激。谢谢!

I've been developing a facebook application that uses a combination of the php sdk and the javascript sdk. It runs in a tabbed iframe on facebook and is hosted on my own server. I'm using the latest php and javascript sdk files as of now (Sept 06, 2011, 2:50PM). The first inconsistency is in the php sdk when getting the user id. This is my code:

require 'fb_php_sdk/facebook.php';

$facebook = new Facebook(array(
    'appId'  => $app_id,
    'secret' => $app_secret,
    'cookie' => true
));

$user = $facebook->getUser();
if ($user) {
    $permissions_granted = true;
} else {
    $permissions_granted = false;
}

This very frequently returns '0' as the facebook ID, no idea why. Though almost as frequently returns the actual facebook id.

The other issue is with images. I often get images not showing up when calling this url:

<img src="https://graph.facebook.com/' . $uid. '/picture/" />

When I use fql I inconsistently get 'undefined' as a result when performing this query:

FB.api(
    {
        method: 'fql.query',
        query: 'SELECT name,pic FROM user WHERE uid=<? echo $user ?>'
    },
        function(response)
        {
            alert(response[0].pic);
        }
);

I really don't understand what would cause this inconsistency and it's making bug testing very difficult. If anyone has experienced this kind of behaviour and can point me in the right direction I'd really appreciate it. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

迷乱花海 2024-12-10 00:28:26

这经常返回“0”作为 facebook ID,不知道为什么。尽管几乎同样频繁地返回实际的 Facebook ID。

当然,因为您的应用程序至少需要默认权限。否则你将无法获得有关用户的任何信息。和你的图像一样。我敢打赌大多数时候你的 $uid 包含数字零。

你检查过 facebook 返回的内容吗?它应该是这样的:

{
“错误”: {
“类型”:“OAuthException”,
"message": "必须使用活动访问令牌来查询有关当前用户的信息。"
}
}

您需要获得用户的权限才能访问他/她的数据。

亲切的问候,
尤里克

This very frequently returns '0' as the facebook ID, no idea why. Though almost as frequently returns the actual facebook id.

Of course, because your app needs at least the default permissions. Otherwise you'll get nothing about the user. And same with your images. I bet most time your $uid contains the number zero.

Did you check what facebook returns? It should be something like:

{
"error": {
"type": "OAuthException",
"message": "An active access token must be used to query information about the current user."
}
}

So you need to get permissions of the user to get access to his/her data.

Kind regards,
Jurik

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文