Reputation: 614
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)?
Upvotes: 2
Views: 1783
Reputation: 614
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.
Upvotes: 0
Reputation: 20753
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.
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)
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.
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!
Upvotes: 1