How to get only photos from user's Facebook newsfeed using graph api?

∥☆過路亽.° 提交于 2019-12-21 06:16:47

问题


I combed through the Facebook documentation but didn't see an obvious way to return ONLY photos on a user's newsfeed. Specifically:

Give a FB access token, I want to get the newsfeed filtered to only photos that were posted.

https://graph.facebook.com/me/home?access_token=

Returns the entire newsfeed. I see that elements have a "Type" attribute, that has a value of "photo" when it's a photo.

How can I scope the response to only return photos?


回答1:


Sure, you can do this using FQL:

SELECT 
    post_id, message, attachment 
FROM 
    stream 
WHERE 
    filter_key 
IN (
    SELECT 
        filter_key 
    FROM 
        stream_filter 
    WHERE 
        uid = me() 
    AND 
        name = "Photos"
   )

Working demo using Graph API Explorer: https://developers.facebook.com/tools/explorer?method=GET&path=fql%3Fq%3DSELECT%20post_id%2C%20message%2C%20attachment%20FROM%20stream%20WHERE%20filter_key%20IN%20(SELECT%20filter_key%20FROM%20stream_filter%20WHERE%20uid%3Dme()%20AND%20name%3D%22Photos%22)

EDIT:

Looks like that link won't work. This is the request to the graph api. You need read_stream permissions.

https://graph.facebook.com/fql?q=SELECT post_id, message, attachment FROM stream WHERE filter_key IN (SELECT filter_key FROM stream_filter WHERE uid=me() AND name="Photos")




回答2:


Facebook has added a filter parameter to the /me/home endpoint so if you query /me/home?filter=photos you get only photos from the users News Feed



来源:https://stackoverflow.com/questions/8542841/how-to-get-only-photos-from-users-facebook-newsfeed-using-graph-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!