Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Facebook graph API to retrieve fan photos uploaded to wall of fan page?

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.

like image 485
Joe Avatar asked Feb 22 '11 20:02

Joe


People also ask

How do I get Facebook Page Insights on graph API?

You can access Page Insights by typing /insights after the name of your page in the URL field. This command will retrieve all of the Insights associated with your Page. Type "/insights" after your company name. Click the Submit button.

Does Facebook graph search still work?

In early June 2019, the feature was further deprecated, with the majority of URLs for graph search queries no longer working. Facebook explained this by saying: "The vast majority of people on Facebook search using keywords, a factor which led us to pause some aspects of graph search and focus more on improving keyword ...


1 Answers

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
]
like image 66
ifaour Avatar answered Oct 26 '22 11:10

ifaour