22 October 2010

How to Query Facebook App User Permissions

The new Facebook Graph API has some neat features and simplifications, but it doesn’t offer a way to query a user’s permissions (looks like an oversight). It lets you request more permissions by going back to the authorization url with extra “scope” parameters, but doesn’t let you actually look up these values. The best solution that I’ve found (at the time of this post) is to use FQL on the permissions table to query any or all of the extended permissions in just one request.

The FQL query looks likes this:

SELECT publish_stream,read_stream FROM permissions WHERE uid = me()

The API request:

https://api.facebook.com/method/fql.query?
    access_token= … &
    format=json&
    query=SELECT%20publish_stream,create_event,rsvp_event,sms,offline_access%20FROM%20permissions%20WHERE%20uid%20%3D%20me()

In the Javascript SDK that looks like:

FB.api(
  {
    method: 'fql.query',
    query: 'SELECT read_stream FROM permissions WHERE uid = me()'
  },
  function(response) { '...' }
);

The response will look like this:

[
  {
      publish_stream: 0,
      create_event: 0,
      rsvp_event: 0,
      sms: 0,
      offline_access: 0
  }
]

or an error like this:

{
  error_code: 190,
  error_msg: 'Invalid OAuth 2.0 Access Token',
  request_args: [ '…' ]
}

Since FQL doesn’t allow SELECT * FROM, you have to specify each permission. If you want to ask for them all, here’s the full list of Facebook app permissions:

publish_stream, create_event, rsvp_event, sms, offline_access, user_about_me, friends_about_me, user_activities, friends_activities, user_birthday, friends_birthday, user_education_history, friends_education_history, user_events, friends_events, user_groups, friends_groups, user_hometown, friends_hometown, user_interests, friends_interests, user_likes, friends_likes, user_location, friends_location, user_notes, friends_notes, user_online_presence, friends_online_presence, user_photo_video_tags, friends_photo_video_tags, user_photos, friends_photos, user_relationships, friends_relationships, user_relationship_details, friends_relationship_details, user_religion_politics, friends_religion_politics, user_status, friends_status, user_videos, friends_videos, user_website, friends_website, user_work_history, friends_work_history, email, read_friendlists, read_insights, read_mailbox, read_requests, read_stream, xmpp_login, ads_management, user_checkins, friends_checkins, manage_pages




Did you find this helpful or fun? paypal.me/mrcoles
comments powered by Disqus

Peter Coles

Peter Coles

is a software engineer living in NYC who is building Superset 💪 and also created GoFullPage 📸
more »

github · soundcloud · rss