有没有办法获取用户当前个人资料图片的 ID?
编辑:好的,看来没有简单的方法来获取 ID!
但随机测试发现,每个用户都有一个具有 type="profile"
属性的相册,并且该相册中的第一张图片始终是个人资料图片,因此可以获取 ID这样的个人资料图片。一些更有 Facebook 经验的人能否证实情况确实总是如此?
Is there a way to get the ID of the picture that is the current profile picture for a user?
Edit: OK, seems there is no trivial way to get the ID!
However, it appears from random testing that every user has a single album with attribute type="profile"
, and the first image in this album is always the profile picture, so it is possible to get the ID of the profile picture that way. Can some more experienced with Facebook confirm that this is indeed always the case?
发布评论
评论(6)
您可以从以下网址获取用户的公开个人资料照片:
https://graph.facebook.com/ [id]/图片
参考:
http://developers.facebook.com/docs/reference/api/
You can get the users public profile photo from the following url:
https://graph.facebook.com/[id]/picture
Reference:
http://developers.facebook.com/docs/reference/api/
答案似乎是是,
例如,相册中的照片有一个ID(尽管个人资料照片是一个不同的对象,它是一个不同的FB ID)。每个对象的 ID 是 FB 新图形 API 的核心概念:社交图中的每个对象都有一个 唯一 ID。
事实上,我通过 FB Graph API 发出的数据请求(成功时)会返回 JSON 数组形式的响应,该响应由嵌套的 ID-值对组成,例如来自用户的教育字段对象:
个人资料照片是连接 用户对象(即每个FB对象都有字段和连接)。
根据相关 FB 开发者页面中的表格,调用 Graph请求图片(用户的个人资料照片)的 API 返回一个字符串,该字符串是用户个人资料图片的 URL。
但为什么同一个调用不返回用户的个人资料照片ID?
我认为原因是 URL 返回:
用户的个人资料照片不在那里,而是在相邻节点中:(
有关 Graph API 结构,请参阅 FB 文档 此处)。
当您进行 API 调用时,请检查请求标头,特别是请求 URL;执行此操作后,您将看到如下内容:
下划线之间的字符串 (100005743929541) 是用户 ID。通过再次调用 Graph API 可以轻松验证这一点。从浏览器地址栏(假设您已登录 Facebook)只需输入:
因此,该 JSON 字符串中的第一项是用户的 FB ID。鉴于此,在我看来,如果用户配置文件 ID 确实有自己的 ID,那么该字符串(用户的 FB ID)加上 ID 两端的两个较小的相邻整数字符串应该就是这样——换句话说,就是上面请求 URL 中的 32093_100005743929541_5467982。
最后,也许回答这个问题的最佳方法是使用新的 Graph API Explorer。 (我只是想验证这一点,但我的请求被挂起。)
The answer seems to be yes
e.g., the photos in an album have an ID (the profile photo is a different object though, which a different FB ID). An ID for every object is a core concept of FB's new graph API: Every object in the social graph has a unique ID.
Indeed, data request i have ever made through the FB Graph API returns (when successful) a response in the form of a JSON array, comprised of nested ID-Value pairs, e.g. the education field from a User object:
The profile photo is a connection of the User object (i.e., every FB object has Fields and Connections).
According to the table in the relevant FB Developer Page, a call to the Graph API requesting picture (user's profile photo(s)) returns a string which is the URL for the user's profile picture.
But why doesn't this same call return the user's profile photo ID?
The reason i suppose is that the URL returns:
The user's profile photo is not there, but in an adjacent node:
(See FB Documentation for Graph API structure here).
When you make that API call, examine the Request Headers, and in particular, the Request URL; when you do, you'll see something like this:
The string between the underscores (100005743929541) is the user ID. this is easy to verify by making another call to the Graph API. From your browser location bar (assuming you are logged into Facebook) just enter:
So again, the first item in that JSON string is the user's FB ID. Given that, it seems to me that if user profile ID does indeed have its own ID, then that string (user's FB ID) plus the two smaller adjacent strings of integers on either end of the ID, should be it--in other words, 32093_100005743929541_5467982 in the Request URL above.
Finally, perhaps the best way to answer this is by using the new Graph API Explorer. (I just tried to verify this, but my requests are hanging.)
有一种更简单的方法可以完成此任务。
获取 https://graph.facebook.com/me/albums? 的所有 Facebook 相册? access_token=.
循环进入相册并检查对象类型是否==“个人资料”。
获取对象 cover_photo 的值,其中 type == 'profile'。
cover_photo 的值是用户个人资料图片的 ID。
您可以通过https://graph.facebook.com/<cover_photo value>?access_tokne=
There is one more simple way to accomplish this task.
Fetch all facebook albums by https://graph.facebook.com/me/albums?access_token=.
Loop into the albums and check if object type == 'profile'.
Get the value of object cover_photo where type == 'profile'.
This value of cover_photo is the id of profile pic of the user.
You can check it by https://graph.facebook.com/<cover_photo value>?access_tokne=
我不知道你是否还需要这个,但这就是我在 PHP 中的做法:
输入你想要的用户 ID,而不是“我”?
I don't know if you still need this but this is the way I did it in PHP:
Instead of "me", put the user id that you want?
SOCIAL-ID = Facebook 返回的社交 ID。
小|正常|相册|大|正方形 = 图像的大小。
SOCIAL-ID = Facebook returned social id.
small|normal|album|large|square = size of image.
我最近尝试从 Graph API 浏览器中点赞我朋友的一张个人资料图片,
以下是我获取他当前个人资料图片 id 的方法:
如果您使用过 Graph API 浏览器,您可能会注意到上面生成的代码行当您勾选复选框时的 textEntry。限制大小由你决定,我只是将其保留为 1 以快速接收 JSON 对象(如果没有限制,我花了 5 分钟才能获取包含大量信息的 JSON 对象)。
因此,您需要在 Graph API 中检查以下内容(保持顺序):
朋友
在朋友相册内
在相册名称和照片中(在照片中照片的 ID 和名称)
我制作了一个 PHP 脚本来喜欢我朋友的所有个人资料图片:)
I recently tried to like one of my friend's profile pictures from the Graph API explorer
Here's how I got the id of his current profile pic:
If you have used the Graph API explorer, you might be aware of the above line of code that's generated in the textEntry when you tick the checkboxes. The limit size is up to you, I just kept it 1 to receive the JSON object quickly (without the limit, it took me 5 minutes to get the JSON object containing a lot of information).
So here are the things you need to check in the Graph API (maintain the order):
Friends
Within Friends Albums
Within Albums Name and Photos (Within Photos the id and name of the photo)
I made a PHP script to like all the profile pictures of my friends :)