搜索朋友的共享YouTube链接

时间:2013-04-08 17:44:24

标签: facebook facebook-graph-api web-applications youtube-api facebook-javascript-sdk

我正在尝试获取朋友分享的所有YouTube视频列表。

直到现在请求/me/home?q=youtube.com确实返回了所有youtube.com链接。 显然,API已更改,现在它似乎只返回邮件正文中包含“youtube.com”的链接。

有没有办法检索某个域的所有共享链接?

1 个答案:

答案 0 :(得分:1)

您必须知道的第一件事是如何获得所需的过滤器密钥,

SELECT filter_key,name FROM stream_filter WHERE uid = me() 

您可以参考https://developers.facebook.com/docs/reference/fql/stream_filter了解详情。

输出的示例部分是:

{
  "data": [
    {
      "filter_key": "nf", 
      "name": "News Feed"
    }, 
    {
      "filter_key": "app_2309869772", 
      "name": "Links"
    }, 

假设您获得了Link filter_key,然后打开https://www.facebook.com/home.php?filter=app_2309869772,主页只显示所有“链接”类型的帖子。

youtube有两种主要类型的视频共享:

第一个是使用youtube网站的分享按钮直接分享,您需要' nf '作为filter_key。然后,您需要按 app_id 进行过滤,即“ 87741124305 ”(您可以参考http://graph.facebook.com/87741124305)。您可以使用 attribution ='Youtube'进行过滤,如果您担心应用ID可能会在将来发生变化。

第二个是用户复制youtube链接并粘贴到墙上。这种帖子可能会显示为'nf'类型。但是,似乎很可能youtube链接不会显示为'nf'类型。因此,您需要使用filter_key“ app_2309869772 ”(链接)来获取这些帖子。当然,我们想要的链接只是youtube视频,所以我们过滤 attachment.caption ='www.youtube.com'

因此,我们在单个fql查询中组合了两个filter_key(News Feed和Links),例如:

SELECT action_links,actor_id,app_data,app_id,attachment,attribution,claim_count,comment_info,created_time,description,description_tags,expiration_timestamp,feed_targeting,filter_key,impressions,is_exportable,is_hidden,is_published,likes,message,message_tags,parent_post_id,permalink,place,post_id,privacy,scheduled_publish_time,share_count,source_id,subscribed,tagged_ids,target_id,targeting,timeline_visibility,type,updated_time,via_id,viewer_id,with_location,with_tags,xid FROM stream WHERE post_id IN (SELECT post_id FROM stream WHERE filter_key in(SELECT filter_key FROM stream_filter WHERE uid=me() AND name='Links') AND attachment.caption='www.youtube.com' AND created_time<=now() LIMIT 150) OR post_id IN(SELECT post_id FROM stream WHERE filter_key in(SELECT filter_key FROM stream_filter WHERE uid=me() AND name='News Feed') AND app_id='87741124305' AND created_time<=now() LIMIT 150) ORDER BY created_time DESC

(您可以根据自己的需要修改链接,如果您不使用此信息,则不打算 action_links

使用https://developers.facebook.com/tools/explorer测试的屏幕截图:

enter image description here

对于这个例子,我每页使用150个项目(我使用大数字,因为实际的帖子是youtube视频并不多)。您可以通过减少created_time来尝试获取下一页,但是,并不能保证每个页面都至少有一个帖子。

引用后的链接(在最后设置访问令牌)将是:

https://graph.facebook.com/fql?format=json&q=SELECT+action_links%2Cactor_id%2Capp_data%2Capp_id%2Cattachment%2Cattribution%2Cclaim_count%2Ccomment_info%2Ccreated_time%2Cdescription%2Cdescription_tags%2Cexpiration_timestamp%2Cfeed_targeting%2Cfilter_key%2Cimpressions%2Cis_exportable%2Cis_hidden%2Cis_published%2Clikes%2Cmessage%2Cmessage_tags%2Cparent_post_id%2Cpermalink%2Cplace%2Cpost_id%2Cprivacy%2Cscheduled_publish_time%2Cshare_count%2Csource_id%2Csubscribed%2Ctagged_ids%2Ctarget_id%2Ctargeting%2Ctimeline_visibility%2Ctype%2Cupdated_time%2Cvia_id%2Cviewer_id%2Cwith_location%2Cwith_tags%2Cxid+FROM+stream+WHERE+post_id+IN+%28SELECT+post_id+FROM+stream+WHERE+filter_key+in%28SELECT+filter_key+FROM+stream_filter+WHERE+uid%3Dme%28%29+AND+name%3D%27Links%27%29+AND+attachment.caption%3D%27www.youtube.com%27+AND+created_time%3C%3Dnow%28%29+LIMIT+150%29+OR+post_id+IN%28SELECT+post_id+FROM+stream+WHERE+filter_key+in%28SELECT+filter_key+FROM+stream_filter+WHERE+uid%3Dme%28%29+AND+name%3D%27News+Feed%27%29+AND+app_id%3D%2787741124305%27+AND+created_time%3C%3Dnow%28%29+LIMIT+150%29+ORDER+BY+created_time+DESC&access_token=

干杯