如何使用 Facebook 图形 API 检索上传到粉丝专页墙上的粉丝照片? [英] How to use Facebook graph API to retrieve fan photos uploaded to wall of fan page?

查看:30
本文介绍了如何使用 Facebook 图形 API 检索上传到粉丝专页墙上的粉丝照片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PHP 和 Facebook 图形 API 创建一个外部照片库.它从我们 Facebook 粉丝页面上的相册中提取缩略图和大图像.

一切正常,除了我只能检索管理员发布到我们页面的照片.(graph.facebook.com/myalbumid/photos) 有没有办法使用graph api来加载粉丝上传的公开照片?

我想从Photos from"相册中检索图片,但尝试获取图形查询的 ID 与其他相册不同...看起来像这样:http://www.facebook.com/media/set/?set=o.116860675007039

另一个注意事项:我接近检索这些数据的唯一方法是使用提要"选项..即:graph.facebook.com/pageid/feed

这大约是我所能得到的 - 它可以工作,但有下面提到的某些问题.也许有人可以对此进行扩展,或者提供更好的解决方案.(使用FB PHP SDK)

api("/YourID/tagged");$maxitem = 10;$count = 0;foreach($photos['data'] as $photo) {if ($photo['type'] == "photo"):echo "<img src='{$photo['picture']}'/>", "<br/>";万一;$count+= 1;if ($count >= "$maxitem") 中断;}?>

问题:

1) 事实上,我不知道查询特定类型"标签的图形方法,我不得不运行条件语句来显示照片.

2) 您不能有效地使用?limit=#",因为正如我所说,标记"查询包含所有类型(照片、视频和状态).因此,如果您要使用照片库并希望避免使用 ?limit 运行整个查询,您将丢失图像.

3) 显示在标记"查询中的唯一内容来自不是页面管理员的人.这不是世界末日,但我不明白为什么 Facebook 不允许自己出现在这些数据中,只要你作为你自己"而不是页面发布它.

解决方案

您需要检索所有相册,然后获取所有照片.这可以通过使用 FQL 轻松完成:

SELECT pid,owner,src_small,src_big从照片哪里有帮助 (选择帮助来自专辑WHERE 所有者 = your_page_id)


您还需要查询流表以获取墙贴,然后检查您是否有附件和附件类型:

SELECT 附件从流哪里 source_id = 116860675007039

结果:

<预><代码>[{依恋": {媒体": [{"href": "http://www.facebook.com/photo.php?fbid=1801693052786&set=o.116860675007039","alt": "测试",类型":照片","src": "http://photos-f.ak.fbcdn.net/hphotos-ak-snc6/185861_1801693052786_15536​​35161_1863491_4978966_s.jpg",照片": {"援助": "6672812206410774346","pid": "6672812206412558147",投标":1801693052786,所有者":15536​​35161,索引":11,宽度":246,高度":198}}],姓名": "",标题": "",描述": "",特性": [],"icon": "http://b.static.ak.fbcdn.net/rsrc.php/v1/yz/r/StEh3RhPvjk.gif","fb_object_type": "照片",fb_object_id":6672812206412558147"}},{依恋": {描述": ""}},...等等]

I am creating an external photo gallery using PHP and the Facebook graph API. It pulls thumbnails as well as the large image from albums on our Facebook Fan Page.

Everything works perfect, except I'm only able to retrieve photos that an ADMIN posts to our page. (graph.facebook.com/myalbumid/photos) Is there a way to use graph api to load publicy uploaded photos from fans?

I want to retrieve the pictures from the "Photos from" album, but trying to get the ID for the graph query is not like other albums... it looks like this: http://www.facebook.com/media/set/?set=o.116860675007039

Another note: The only way i've come close to retreiving this data is by using the "feed" option.. ie: graph.facebook.com/pageid/feed

EDIT: This is about as far as I could get- it works, but has certain issues stated below. Maybe someone could expand on this, or provide a better solution. (Using FB PHP SDK)

<?php
require_once ('config.php');
// get all photos for album
$photos = $facebook->api("/YourID/tagged");
$maxitem =10;
$count = 0;
foreach($photos['data'] as $photo) {
    if ($photo['type'] == "photo"):
        echo "<img src='{$photo['picture']}' />", "<br />";
    endif;
    $count+= 1;
    if ($count >= "$maxitem") break;
}
?>

Issues with this:

1) The fact that I don't know a method for graph querying specific "types" of Tags, I had to run a conditional statement to display photos.

2) You cannot effectively use the "?limit=#" with this, because as I said the "tagged" query contains all types (photo, video, and status). So if you are going for a photo gallery and wish to avoid running an entire query by using ?limit, you will lose images.

3) The only content that shows up in the "tagged" query is from people that are not Admins of the page. This isn't the end of the world, but I don't understand why Facebook wouldn't allow yourself to be shown in this data as long as you posted it "as yourself" and not as the page.

解决方案

You need to retrieve all the albums and then get all the photos. This can be easily done by using FQL:

SELECT pid,owner,src_small,src_big 
FROM photo 
WHERE aid IN (
    SELECT aid 
    FROM album 
    WHERE owner = your_page_id
)

EDIT:
Also you need to query the stream table to get the wall posts then check if you have attachments and the type of the attachment:

SELECT attachment
FROM stream 
WHERE source_id = 116860675007039

Result:

[
  {
    "attachment": {
      "media": [
        {
          "href": "http://www.facebook.com/photo.php?fbid=1801693052786&set=o.116860675007039",
          "alt": "test",
          "type": "photo",
          "src": "http://photos-f.ak.fbcdn.net/hphotos-ak-snc6/185861_1801693052786_1553635161_1863491_4978966_s.jpg",
          "photo": {
            "aid": "6672812206410774346",
            "pid": "6672812206412558147",
            "fbid": 1801693052786,
            "owner": 1553635161,
            "index": 11,
            "width": 246,
            "height": 198
          }
        }
      ],
      "name": "",
      "caption": "",
      "description": "",
      "properties": [],
      "icon": "http://b.static.ak.fbcdn.net/rsrc.php/v1/yz/r/StEh3RhPvjk.gif",
      "fb_object_type": "photo",
      "fb_object_id": "6672812206412558147"
    }
  },
  {
    "attachment": {
      "description": ""
    }
  },
...etc
]

这篇关于如何使用 Facebook 图形 API 检索上传到粉丝专页墙上的粉丝照片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆