13

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).

Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
Daniel Greaves
  • 987
  • 5
  • 24
  • Have you tried running your app as a non-admin user, or have you only tested it as the app admin? If the latter, try running as a non-admin user. – Relaxing In Cyprus Dec 22 '12 at 22:42
  • Incidently, I tried to replicate your problem using both a tabbed app and a separate site, but have been unable to do so. Could you tell me, is your client the owner of the facebook page, as well as the tabbed app? I would have thought they must be but don't want to assume anything. – Relaxing In Cyprus Dec 22 '12 at 23:53
  • Are you sure this isn't due to this bug? – Igy Dec 23 '12 at 15:21
  • @FacebookAnswers Yes the facebook user that I have been testing with is the owner of the app and has admin access to the page that the tab exists on. The user does not have admin access to the pages that I am trying to fetch posts for though. Perhaps I will try with a user that does not own the app (although this seems like a strange way for the API to function). – Daniel Greaves Dec 24 '12 at 10:00
  • @Igy You haven't provided any link to a bug. – Daniel Greaves Dec 24 '12 at 10:01
  • @FacebookAnswers I have added an update to my question whereby I have run through the process using my personal account (that has no relation to the app or any of the pages in question). Unfortunately, the same result occurs. It is strange that you cannot replicate the issue. – Daniel Greaves Dec 24 '12 at 10:34
  • With regards to admin / non admin users, I mentioned that because I had experienced problems when testing as an admin user on a variety of FB related projects. I have no idea why its the case, but its an easy thing to rule out by a simple test, so its always one of the first things I try if I hit a wall. – Relaxing In Cyprus Dec 24 '12 at 13:45
  • @FacebookAnswers Thanks. I will bear that in mind for the future and based on the test in my update, can safely rule that out of the equation! – Daniel Greaves Dec 24 '12 at 16:14
  • Sorry, you're correct - i didn't include a link to the bug: https://developers.facebook.com/bugs/444783718917323 – Igy Dec 25 '12 at 18:44
  • @Igy Thanks for the link. That bug does appear to be somewhat similar to this situation. However, it hasn't been updated by Facebook since November which is a pain! – Daniel Greaves Dec 26 '12 at 11:58
  • It's not clear from the public-visible part of that bug report, but some of the repro steps people added are about making a POST to /feed, receiving a post ID in the response, but that post ID not working – Igy Dec 26 '12 at 13:42

3 Answers3

9

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.

Chenna V
  • 10,185
  • 11
  • 77
  • 104
Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
2

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.

arttronics
  • 9,957
  • 2
  • 26
  • 62
1

When you make a post via the API, Facebook returns to you the ID of that post. You can save these IDs and then query for them later with the graph API or FQL

Fisch
  • 3,775
  • 1
  • 27
  • 38
  • Fisch, thanks for your reply. I have updated my post above in response. Unfortunately, Facebook isn't letting my look the post up by it's ID either. Almost as if it is non existent to the API. – Daniel Greaves Dec 19 '12 at 11:46