2
votes

This is similar to questions asked several times before, but no matter what I read, I'm still confused.

I have a public Facebook page, like White Collar for example, whose activity feed I need to embed into my Android app. I understand how to get the app-id and app-secret, but I don't understand how to get the short-lived access token, which I understand is necessary to get a long-lived access token.

From what I understand, which can quite possibly be wrong, the user has to login through the app to get a short-lived access token, but I don't want any user to have to login to view the activity feed.

Once I have that, how do I then use it to bring this activity feed into my app?

The Facebook documentation for this is terrible so I need some help.

If it or anything else requires site-specific permissions, I have access to the site in question.

Thanks!

1

1 Answers

14
votes

To get the activity feed of a public Facebook page, like White Collar, follow these steps:

1) Get your App-id and App-secret by choosing an existing app or creating a new one at this url:

https://developers.facebook.com/apps/

2) Get an access token by making a GET request to this url:

https://graph.facebook.com/oauth/access_token?client_id=" + APP_ID + "&client_secret=" + APP_SECRET + "&grant_type=client_credentials

3) Get the page-id of your fan page. To do this, you need the page-name. Go to your fan page on facebook and look at the url. It will have this form:

https://www.facebook.com/{fan-page-name}

Once you have that, make a GET request to this url:

https://graph.facebook.com/{fan-page-name}?access_token={access-token}

It will return a bunch of JSON. You're looking for the first "id" element. This is your page-id.

4) Get the fan page JSON data with a GET request to this url:

https://graph.facebook.com/" + page-id + "/feed?access_token=" + URLEncoder.encodeUTF8(access-token)

To avoid having exceptions thrown, I had to use URLEncoder.encodeUTF8(). The data you're looking for is under the "data" element.

I wasn't able to find anything that would do the JSON parsing of the Facebook feed for me, but I did find this tutorial that will do a lot of the formatting for you to make it look like Facebook.

Hope that helps anyone else trying to do this.