How to check if some access_token of FB is valid in Rails?

1.2k views Asked by At

I know that there is Koala gem for Rails to work with Facebook. I need to make clear 2 things:

  1. How to check if some access_token is valid in Rails using Koala (or something else)?
  2. How to generate some real access token (using some settings of my app or my login/password) for testing through RSpec?

Thanks in advance.

1

There are 1 answers

0
blotto On

For #1 Use the Tool https://developers.facebook.com/tools/debug if you don't want to code a test. Otherwise hit this API and verify the response.

https://graph.facebook.com/oauth/access_token_info?client_id={APP_ID}&access_token={ACCESS_TOKEN}

For #2, Koala has a good API for accessing Facebook Test Users, which I recommend for use in Rspec.

We also support the test users API, allowing you to conjure up fake users and command them to do your bidding using the Graph or REST API:

 @test_users = Koala::Facebook::TestUsers.new(:app_id => id, :secret => secret)
 user = @test_users.create(is_app_installed, desired_permissions)
 user_graph_api = Koala::Facebook::API.new(user["access_token"])
 # or, if you want to make a whole community:
 @test_users.create_network(network_size, is_app_installed, common_permissions)

You can also create Test User in the App Settings from Facebook, and view thier details from this API :

 https://graph.facebook.com/{APP_ID}/accounts/test-users?%20access_token={APP_TOKEN}