Java Reference
In-Depth Information
Accessing Facebook
try it out
This exercise demonstrates how to use the REST service of Facebook. It assumes that you already have
and includes a list of all the resources you can access.
1.
To access the Facebook Graph API, you'll first need to register as a developer. This can be done by
Apps in the upper menu.
2.
Next, just as for Twitter, you need to create a set of keys under
https://developers.facebook
.com/tools/accesstoken/
.
Create a new app, give it a unique name, and select a category.
3.
After creating your app, you'll be brought to your app's “Dashboard,” which contains a wealth of
information and settings to play with. See Figure 10-24.
figure 10-24
4.
Be sure to note your “App ID” and “App Secret” keys. Click + Add Platform, choose website, and
you're not the owner of this domain, it'll work fine to extract the callback URL (together with the
access token) and copy it in your application. Don't forget to save your changes.
5.
Facebook uses a complicated login flow with the possibility to modify many options and permis-
sions, inspired by OAuth but not exactly the same. The page on manually building a login flow,
6.
Create a single class, called
FacebookTest
, using the following code:
package com.facebook.graph;
import java.awt.Desktop;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
Search WWH ::
Custom Search