Facebook Graph API 调用成功返回我的用户信息,但没有返回我的相册?

发布于 2024-11-08 21:40:21 字数 2340 浏览 0 评论 0原文

问题是:这是我的大脑吗?还是 Facebook 令人恼火的 API?

意图: 返回我的 Facebook 相册信息和用户信息

结果:相册信息的空数据集,用户信息的完整结果

{
   "data": [

   ]
}


<?php
/****************************************************************************
Application settings
****************************************************************************/
$app_id = '123456';
$app_secret = "4543163864";
$my_url = "http://www.myurl.com/app";
$canvas_page = 'http://apps.facebook.com/my_canvas_page/';

# authorize the user using oauth protocol (including required permissions)
$auth_url = "http://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page)."&scope=user_photos,friends_photos";

     $signed_request = $_REQUEST["signed_request"];
     list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
     $fb_user_session = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

    # if authorization failed, kick back to auth_url
    if (empty($fb_user_session["user_id"])) 
    {
        echo("<script> top.location.href='" . $auth_url . "'</script>");
    } 
    else 
    {
        /****************************************************************************
        User successfully logged in.
        ****************************************************************************/
        $my_albums = "https://graph.facebook.com/me/albums?access_token=".$fb_user_session['oauth_token'];
        $my_info = "https://graph.facebook.com/me?access_token=".$fb_user_session['oauth_token'];



        echo "<a href='$my_albums'>my album information</a><br>";
        echo "<a href='$my_info'>my user information</a>";

        ### ignore this, just testing iframe call ###
        exit;
        echo("<script> top.location.href='" . $my_albums . "'</script>");
    } 
?>

其他信息: 测试来自 http://developers.facebook.com/docs/reference 的“相册”请求/api/user/ 登录后有效!它成功返回了我所有的专辑信息。但我注意到测试 URL 中的授权令牌与我检索到的应用程序令牌 ($fb_user_session['oauth_token']) 不同。这是怎么回事?

我是否缺少某种授权步骤?为什么我的应用程序会使用完全相同的调用和返回我的相册的空数据?令牌,而 Facebook 的测试调用返回全套?如果有人可以帮助一劳永逸地解决这个问题,那就太棒了。

有什么想法吗?

The question is: is it my brain? Or Facebook's infuriating API?

Intention:
Return my facebook album information and my user information

result: empty data set for album information, full result's for user information

{
   "data": [

   ]
}


<?php
/****************************************************************************
Application settings
****************************************************************************/
$app_id = '123456';
$app_secret = "4543163864";
$my_url = "http://www.myurl.com/app";
$canvas_page = 'http://apps.facebook.com/my_canvas_page/';

# authorize the user using oauth protocol (including required permissions)
$auth_url = "http://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page)."&scope=user_photos,friends_photos";

     $signed_request = $_REQUEST["signed_request"];
     list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
     $fb_user_session = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

    # if authorization failed, kick back to auth_url
    if (empty($fb_user_session["user_id"])) 
    {
        echo("<script> top.location.href='" . $auth_url . "'</script>");
    } 
    else 
    {
        /****************************************************************************
        User successfully logged in.
        ****************************************************************************/
        $my_albums = "https://graph.facebook.com/me/albums?access_token=".$fb_user_session['oauth_token'];
        $my_info = "https://graph.facebook.com/me?access_token=".$fb_user_session['oauth_token'];



        echo "<a href='$my_albums'>my album information</a><br>";
        echo "<a href='$my_info'>my user information</a>";

        ### ignore this, just testing iframe call ###
        exit;
        echo("<script> top.location.href='" . $my_albums . "'</script>");
    } 
?>

Additional information:
Testing an 'album' request from http://developers.facebook.com/docs/reference/api/user/ while logged in works! It successfully returns all my album info. But I noticed the authorization token in the test URL is different from my retrieved application token ($fb_user_session['oauth_token']). What is going on here?

Am I missing some kind of authorization step? Why would my application return empty data for my albums using the exact same call & token while Facebook's test call returns a full set? If anyone can help solve this problem once and for all, that would be awesome.

Any ideas?

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

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

发布评论

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

评论(1

月隐月明月朦胧 2024-11-15 21:40:21

尝试将“user_photo_video_tags”添加到请求的范围列表中。另外,尝试调用权限 api 调用,通过检查“user_photos”权限来确保您有权访问用户的照片。
网址为: https://graph.facebook.com/me/permissions?access_token=...

Try adding "user_photo_video_tags" to the list of scopes requested. Also, try calling the permissions api call to make sure you have access to the user's photos by checking the "user_photos" permission.
The url is: https://graph.facebook.com/me/permissions?access_token=...

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