How to Create a Facebook App
QUICK TIP! How to find your Facebook oauth key
- Visit the following address: http://developers.facebook.com/tools/explorer/
- Click 'Get Access Token'
- Check all of the boxes on the User Data Permissions tab.
- Check the Read_Stream box on the Extended Permissions tab and click 'Get Access Token'
- You can now copy your oAuth token and uid into the appropriate fields on the ImportToken call
Creating your own Facebook app
1. Add the Facebook Developer App to your profile: http://developers.facebook.com/apps (if you have not already done so)
2. Go to developers.facebook.com and select Apps from the header bar.
3. Fill in the following information:
- Display Name: the name of your app as it will appear in facebook auth dialogues.
- Namespace: the Facebook URL of your app. You will not be sending anyone directly to this URL but you still need to define one.
- App Domain: this is the domain of the website where you will be hosting your app.
4. Under 'Select how your app integrates with Facebook', choose the Website option and enter your site URL.
5. Now Select 'Auth Dialogue' from the Settings Area. Fill in as much of this information as you prefer. The information you enter here will appear in the auth dialogue box that the user sees. It is a good idea to give them enough information that they feel comfortable approving your app.
The permissions required for Whit.li analytics API are as follows
6. You do not need to change any of the settings on the Advanced page of your App unless you feel comfortable doing so.
7. Create a button on the homepage of your app that allows users to approve access to Facebook. Sample code below:
<a href="https://facebook.com/dialog/oauth?client_id=23525741655XXXX&redirect_uri=https://www.domainname.com/&scope=email,user_about_me,user_activities,user_birthday,user_education_history,user_groups,user_hometown,user_interests,user_likes,user_location,user_relationships,user_relationship_details,user_religion_politics,user_subscriptions,user_website,user_work_history,user_events,user_games_activity,user_notes,user_photos,user_status,user_videos,read_stream">Login with Facebook</a>
- You will need to replace the number after client_id= with the App id for your Facebook app.
- You will also need to replace the url after redirect_uri= with the page you would like facebook to return the user to.
- The scope as defined in this example allows you access to all available user data. You can modify this scope as you see fit by removing any of the items you do not need from the url above.
- [For more information on the authentication flow visit: https://developers.facebook.com/docs/authentication/]
- [For more information on permissions and scopes visit: https://developers.facebook.com/docs/reference/api/permissions/]
8. Once the user clicks the button above, there are a few options as to what will be returned:
- If your app is successfully authenticated and the authorization code from the user is valid, the authorization server will return the access token.
- In addition to the access token (the access_token parameter), the response contains the number of seconds until the token expires (the expires parameter). Once the token expires, you will need to re-run the steps above to generate a new code and access_token, although if the user has already authorized your app, they will not be prompted to do so again.
- If there is an issue authenticating your app, the authorization server will issue an HTTP 400 and return the error in the body of the response:
"message":"facebook returned an error",
"errorString":"Error validating access token: User 1431826611 has not authorized application 235257416558070."
9. Once an access token has been successfully returned, you can pull the Facebook users information by using the Graph api. The Graph API presents a simple, consistent view of the Facebook social graph, uniformly representing objects in the graph (e.g., people, photos, events, and pages) and the connections between them (e.g., friend relationships, shared content, and photo tags).
All responses are JSON objects.
Here are some example calls (replace 'uid' with a valid Facebook uid):
- Friends: https://graph.facebook.com/uid/friends?access_token=
- News feed: https://graph.facebook.com/uid/home?access_token=
- Profile feed (Wall): https://graph.facebook.com/uid/feed?access_token=
- Likes: https://graph.facebook.com/uid/likes?access_token=
- Movies: https://graph.facebook.com/uid/movies?access_token=
- Music: https://graph.facebook.com/uid/music?access_token=
- Books: https://graph.facebook.com/uid/books?access_token=
- Notes: https://graph.facebook.com/uid/notes?access_token=
- Permissions: https://graph.facebook.com/uid/permissions?access_token=
- Photo Tags: https://graph.facebook.com/uid/photos?access_token=
- Photo Albums: https://graph.facebook.com/uid/albums?access_token=
- Video Tags: https://graph.facebook.com/uid/videos?access_token=
- Video Uploads: https://graph.facebook.com/uid/videos/uploaded?access_token=
- Events: https://graph.facebook.com/uid/events?access_token=
- Groups: https://graph.facebook.com/uid/groups?access_token=
- Checkins: https://graph.facebook.com/uid/checkins?access_token=