【问题标题】:FaceBook downloading photos using php-sdkFacebook 使用 php-sdk 下载照片
【发布时间】:2011-09-10 02:58:47
【问题描述】:

我是 Facebook PHP SDK for Graph API 的新手。
我在 Facebook 上创建了一个应用程序,并获得了应用程序 ID、秘密 ..etc。
我还使用范围参数获得了具有某些权限的访问代码。

使用该代码,我获得了离线访问的访问令牌。

https://graph.facebook.com/oauth/access_token?client_id=xxxxxxxxxx&redirect_uri=http://192.168.15.5/xxxx/facebook/&client_secret=xxxxx&grant_type=client_credentials。

使用这个我得到了访问令牌。 现在我的问题是我想访问照片和好友列表等用户信息

不知道对不对,

https://graph.facebook.com/me/friends?access_token=xxxxxxxxxxxxxxxxxxxxx

当我使用它时,它会说,

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

如何使用该用户的访问令牌访问用户信息。 对于允许我的应用程序访问其信息的用户,我想随时从应用程序访问用户信息。

【问题讨论】:

    标签: facebook-graph-api facebook-php-sdk


    【解决方案1】:

    如果您使用 Facebook PHP SDK (see on github),请不要直接调用这些 URL,而只能调用 SDK 的函数。

    查看此答案以了解如何获取和使用离线访问令牌进行 API 调用:How to login with offline_access using the new Facebook PHP SDK 3.0 ?

    然后要获取用户朋友和他们的照片,你会调用:

    $args = array("fields" => "name,picture");
    $friends = $facebook->api('/me/friends', $args);
    

    那么数组$friends['data']将包含好友图片的URL:

    Array( 
        [0] => Array(
            [name] => Quentin Pleplé
            [id] => 1536397056
            [picture] => http://profile.ak.fbcdn.net/...jpg
        )
        [1] => ...
        ...
    )
    

    希望有帮助!

    【讨论】:

    • 非常感谢。请你告诉我如何使用 access_token 获取用户的照片,然后将这些照片存储在我计算机上的驱动器上。谢谢
    • 嗨,Asghar,我编辑了我的答案,向您展示如何获取图片。这是你需要的吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多