Get wall feed from a public Facebook page using Graph API - is it really this complex?

喜你入骨 提交于 2019-12-20 10:40:21

问题


I have started off by reading Displaying Facebook posts to non-Facebook users which is of some use but I cannot believe it is this difficult to get a public feed from Facebook.

The page I want a feed from is public, you do not need to be logged into get to it.

Am I right in presuming that I need an access_token to get to this information, attempting to access the URL without results in an OAuth error.

So the flow should be like this (massively, overly complex):

  1. Authenticate using a user (what if the user isn't on Facebook?)
  2. Some complex OAuth nonsense - just to read the feed, I do not even want a like button or post to wall functionality
  3. Get the feed using a PHP request to the correct URL with the user's access_token
  4. Render the feed

Assuming the user isn't on Facebook, what do you do, use a generic app to get the feed?

  1. Hardcode an auth request to Facebook using my generic app's ID and secret
  2. Some complex OAuth nonsense
  3. Get the feed using a PHP request to the correct URL with the app's access_token
  4. Render the feed
  5. Oh no, the auth has expired, re-auth and capture this new access_token for use in future requests.

This seems really complex for no reason other than Facebook wants to know EVERYTHING that is going on, it'd be easier to do a cURL and scrape the content from the public URL using XPath.

Any help on this would be great.

Thanks, Jake

EDIT

An edit to show this is not an exact duplicate.

I had this working with an access_token in place, but now it fails, the token has expired and I can no longer use it to obtain information from the public wall.

I attempted to extend the expiration date of this token using the methods mentioned in other posts but this didn't work and the expiration was not extended - we are now here, with an invalid token and no further along.

It seems that the manual process of having to approve the OAuth request means that it is impossible to programatically get the feed of a public page.


回答1:


Two years later, you can programmatically do this with a Facebook App (an example using PHP and Slim): https://developers.facebook.com/apps/

$base_api="https://graph.facebook.com/";
$client_id="XXXXXX";
$app_secret="XXXXXX";

//get a profile feed (can be from a page, user, event, group)
$app->get('/feed/:profileid/since/:start_date', function ($profile_id,$start_date) {

    $start_time=date('m/d/Y h:i:s',$start_date);

    $request = new FacebookRequest(
      getSession(),
      'GET',
      '/'.$profile_id.'/feed?since='.$start_time
    );

    $response = $request->execute();
    $graphObject = $response->getGraphObject();

    //do something with $graphObject

});


function getSession(){
    $session = new FacebookSession(getAccessToken());
    return $session;
}


function getAccessToken(){
    global $base_api, $client_id, $app_secret;
    $url=$base_api."oauth/access_token?client_id=".$client_id."&client_secret=".$app_secret."&grant_type=client_credentials";
    $str = file_get_contents($url);
    $token = str_replace ( "access_token=" , "" , $str );
    return $token;
}



回答2:


I have some success with reading in the direct feed without tokens etc. (using magpie, simplepie or querypath or similar).

http://www.facebook.com/feeds/page.php?format=rss20&id=........ http://www.facebook.com/feeds/page.php?format=atom10&id=........

found on: http://ahrengot.com/tutorials/facebook-rss-feed/




回答3:


Facebook has changed how to retrieve a public Facebook page's feed since the other answers were posted.

Check out my answer/question. It's not PHP, but it provides the URLs and process you need.



来源:https://stackoverflow.com/questions/9759386/get-wall-feed-from-a-public-facebook-page-using-graph-api-is-it-really-this-co

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!