Pulling data using the Facebook graph API

https://i2.wp.com/www.digitaltrends.com/wp-content/uploads/2013/03/facebook-graph-search-icon.jpg

The facebook api is erroneous, or, I could be a complete idiot and not know how to read. Here I will show you the PROPER way to make calls to the facebook graph api. It’s so stupidly simple that perhaps the developers at facebook decided not to put this information on the the front page of their developer site.

Ok, no more pain. Here is what you do. Let’s say you want to accomplish this task:
1) Obtain your notification in .json format so you can parse through them using your java program.

Easy. Now this step assume you’ve already gone through oauth and have a valid access token. I won’t bother touching on the oauth process of the facebook api, its equally stupid.

Rather, I recommend using www.temboo.com  for your oauth needs. It supports the facebook oauth process nicely and all you really have to do is copy paste their auto generated code and that process should spit out an accesstoken for you to use for this step.

So here we go. To access your UNREAD, FACEBOOK NOTIFICATIONS, simply parse this URL

https://graph.facebook.com/me/notifications?access_token=YOUR_TOKEN_HERE

Here, me is referring to the authenticated user and notifications refers to .json formatted list of your unread notifications. Maintain the ? after the last thing you put for this call, then add the access token exactly as you see it.

Let’s take this out on a sample run. I’m going directly to the graph api explorer and snatching a pre generated access token.

Go here, https://developers.facebook.com/tools/explorer/

Then, click on “Get Access Token”, go to “Extended Permissions” and check “manage_notifications”

Copy paste the Access token that is generated. Cool. Now paste that access token like I said before and go to the link.
You should get a nicely formatted JSON response that looks like this:

response

 

 

 

 

 

YAY. Now you can parse the url. I won’t go over that here. That tutorial’s already been done.
Go here.

Hope that helps. I swear to God if someone else had this article, it would’ve saved me a good 3 hours.

 

Advertisements

Tell me what you think!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s