FacebookGraphHandler offers a proxy for the Facebook Graph API. Here is an example:
url:
facebook:
pattern: /facebook/(.*)
handler: FacebookGraphHandler
kwargs:
# Visit https://developers.facebook.com/apps/ to get these keys
key: ... # App ID
secret: ... # App Secret
redirect:
header: Referer
url: /$YAMLURL/
Follow the steps for Facebook auth to get the keys above.
Now, follow these steps:
The request below will show your name once you log in. To log in, visit /facebook/:
$.get("facebook/me"); // OUTPUT
After the OAuth login, users can be redirected via the redirect:
config
documented the redirection configuration.
The FacebookGraphHandler is very similar to the TwitterRESTHandler in many ways:
path:
configuration to hard-code a specific request. See the
Twitter pathstransform:
configuration to modify the response in any way.
See the Twitter transforms
documentation.POST
, you can use the GET
method as well. See the documentation
on Twitter GET requestsSee this sample application and its source for examples of usage.
If your app needs to persist the user’s access token, add access_token: persist
to the kwargs. The first time, the user is asked to log in. Thereafter, the
user’s credentials are available for all future requests.
This is typically used to show the latest posts / photos of a user or page on every visit. Typically, such requests are cached as well. Here is a sample configuration:
url:
facebook-persist:
pattern: /persist/(.*)
handler: FacebookGraphHandler
kwargs:
key: "..."
secret: "..."
access_token: persist # Persist the access token after first login
cache:
duration: 300 # Cache requests for 5 seconds
Here is a sample response:
$.get("persist/me"); // OUTPUT
The first time, you get an access_token error. Visit /persist/ to log in. Thereafter, your access_token will be stored and used for future requests until it expires, or a user logs in again at /persist/.