2

I'm building an iOS & Android app with Phonegap and I want to include a feature that reads a particular Facebook wall using the /posts endpoint, without requiring the user to log in - many of them will not have their own Facebook account anyway. So ideally the app should have an access token built in.

Creating a Facebook app just to get an access token sounds like overkill, and the official Phonegap plugin requires user login. All I need, really, is to authenticate as a generic user (maybe using my own account) and pull the JSON using the API. No write permissions are needed.

Anyone have any ideas about the simplest way of doing this (robustly)?

Kwoxford
  • 624
  • 7
  • 11
  • 1
    Possible duplicate of [Can you get a public Facebook page's feed using Graph API without asking a user to allow?](http://stackoverflow.com/questions/9373645/can-you-get-a-public-facebook-pages-feed-using-graph-api-without-asking-a-user) – Suhaib Jul 31 '16 at 23:31

2 Answers2

1

First of all without using any access token you can not read posts from any wall whether it be of a user or a page.

  1. Now, if you want to escape the user authentication, you can use the app access token (app_id|app_secret) to get public posts by a page or user.

    eg: https://graph.facebook.com/sahilmittal/posts?access_token={app-access-token}
    [public posts from a user]

    eg: https://graph.facebook.com/AamAadmiParty/posts?access_token={app-access-token}
    [public posts from a page]

    (remember, dont expose app access token on a client side- its just like a password for your app)

  2. If the posts are not public, but visible to a user, you will be needing an active user access token (it expires eventually) of that user to view such posts.

  3. If you want to fetch posts of a page, then using page access token, you can fetch all the posts by that page.

    So, if you are looking to fetch the posts from a page administered by yourself, you can get the page access token, extend it (after extension it never expires) and use that token to get the feeds. Here are the steps to get a never expiring page access token

Hopt it helps. Good luck!

Community
  • 1
  • 1
Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
0

I followed the advice above and built a tiny little php script, like this:

parse_str($_SERVER['QUERY_STRING']);

$authToken = "APP_ACCESS_TOKEN_GOES_HERE";

$graph_url = "https://graph.facebook.com/".$id."/posts?access_token=".$authToken;

$json_object = file_get_contents($graph_url);

echo $json_object;

Works like a dream. Just hit it with id=whatever and json comes shooting out.

Kwoxford
  • 624
  • 7
  • 11