Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetching third party posts from the Facebook Graph API

I am in the process of putting together a Facebook tab application for a client that fetches and displays posts from a Facebook page. The application also offers the ability to add new posts to the page and comment on existing posts. This is achieved using the Facebook Graph API (through the the PHP SDK).

I have everything working but have run into a problem involving posting from my app. When a user submits a post, it is sent to the Graph API via the following request.

$facebook->api([PAGE_ID]/feed', 'POST', array(
    'message' => [MESSAGE]
));

This request is successful and the post appears on the relevant Facebook page with "Via my app name" underneath it.

When I then request the list of posts on the Page via the API (request below), the aforementioned post does not appear.

$posts = $facebook->api([PAGE_ID].'/feed');

I have a strong feeling that this is due to the post being from a third party app. I have heard that Facebook "downgrades" third party posts to encourage the use of its own platform. All of the posts that were posted directly through Facebook are appearing.

However, there must be a way to retrieve these kind of posts.

Update for Fisch below

When I make the post to the API, the following post ID is returned:

112706495458566_468411663221379

However, when I make an API request for it:

$facebook->api('112706495458566_468411663221379');

I get the following response:

{
    "error": {
        "message": "Unsupported get request.",
        "type": "GraphMethodException",
        "code": 100
    }
}

However, when I make the same request but with the ID of a post already included in the /feed request.

$facebook->api('112706495458566_457890310940181');

I get the following response.

{
    "id": "112706495458566_457890310940181",
    "from": {
        "category": "Local business",
        "name": "Genting Casino Southport",
        "id": "112706495458566"
    },
    "story": "\"Very well done to ste,...\" on their own status.",
    "privacy": {
        "value": ""
    },
    "type": "status",
    "application": {
        "name": "Mobile",
        "id": "2915120374"
    },
    "created_time": "2012-11-25T22:12:21+0000",
    "updated_time": "2012-11-25T22:12:21+0000",
    "comments": {
        "count": 0
    }
}

So for some reason, Facebook isn't even letting me look up the post by its ID.

Update #2

In my search for an answer to this, I have come across a study which strengthens my earlier suspicions about the "weight" assigned to third party app posts.

From the EdgeRank Checker report: "When an object is created in Facebook, it is assigned a weight. We believe that Facebook strategically reduced the weight of objects created through the API. The reason behind this strategy would be to encourage more content creation within the Facebook Platform. This ultimately increases the value of their platform while increasing ad impressions."

http://adage.com/article/digitalnext/posting-facebook-truth-party-applications/229694

This could explain why the posts are not passed through in the /feed or /posts API response.

However, this does not explain why the API will not even return the post by it's ID (see update above).

All I can think of is that Facebook does not class third party app posts as real "Posts" and thus doesn't push them through on the appropriate API response. However, I can find no evidence of this in the Facebook documentation.

Update #3

Based on the comments below, I am now attempting to do the same but using a Facebook account that is not the owner of the app or in fact has any admin relation to any page on Facebook (my own personal Facebook account).

I have authorised the app using the oAuth dialog and have accepted the following permisions:

  • email
  • user_birthday
  • publish_stream

With my shiny new access token, I make the following API request:

$post = $facebook->api('112706495458566/feed', 'POST', array(
    'message' => 'this is a test'
));

To which I receive the following response:

array(1) {
    ["id"] => string(31) "112706495458566_470663409662871"
}

I then check the actual Facebook page, the post that I just sent has appeared from my Facebook user account as expected.

I then make the following request to fetch all posts on the page:

$posts = $facebook->api('112706495458566/feed');

To which I receive a long array of all the posts on the page (which I wont post here). However, the post that I just sent (and received an ID back for) does not appear.

I then make a direct request for that post using the ID that was returned by the POST request.

$post = $facebook->api('112706495458566_470663409662871');

Which throws the following exception (as per the previous attempt).

GraphMethodException: Unsupported get request.

To reiterate, this attempt was using an account that is completely unrelated to the app or any of the pages that we are trying to fetch data for. The account has also never had any contact with the app (i.e. this was the first time that the permissions have been accepted and an oAuth key generated).

like image 397
Dan Greaves Avatar asked Dec 19 '12 10:12

Dan Greaves


2 Answers

Dan, I tried this-

  1. POST a feed from an APP to a Page

    POST: "PAGE_ID/feed"
    message: "hi"
    

    Result: Post Successful

  2. Request the list of posts on the Page

    GET: "PAGE_ID/feed"
    

    Result: All the posts on the Page incl the aforementioned post.


Why it worked?

Because the GET request was made using the access token of the user who is the admin of the app through which the message was posted.

Conclusion

I tried all the cases and final conclusion is that, to fetch the feeds of a page incl that are posted by some APP, you have to use the access token of the admin of that app (not a big issue); else you'll just get the rest of the feeds.

like image 196
Sahil Mittal Avatar answered Oct 28 '22 20:10

Sahil Mittal


Use a combination of Yahoo Query Language and .ajax() to data scrape the Facebook Feed Channel.

The benefit about data-scraping the LIVE Facebook Member Webpage is you don't need token key to get the latest real-time feeds!

HTML:

<div id="results"></div>

jQuery:

$.ajax({
    url: "http://query.yahooapis.com/v1/public/yql",
    dataType: "jsonp",
    success: function(data) {
        console.log(data.query.results.json);
        $.each(data.query.results.json.entries, function(i, v) {
            $('#results').append(data.query.results.json.entries[i].content + '<br /><br />');
        });
    },
    data: {
        q: 'select * from json where url="https://www.facebook.com/feeds/page.php?id=112706495458566&format=json"',
        format: "json"
    }
});

DEMO: Inspired by this online tutorial.

jsFiddle Facebook Feeds


EDIT: Click image for revised jsFiddle with Style


EXTRA:

To complement my answer above, here is quasi-related jsFiddle titled:

jsFiddle Tutorial: Creating Dynamic Div's (Now Improved!)

This tutorial shows how to convert your HTML markup so it becomes a "template" that is ready to use with jQuery as an Object, which then can be appended to the webpage correctly.

like image 35
arttronics Avatar answered Oct 28 '22 19:10

arttronics