2

I've been trying to use my RoR app to connect to the Facebook API for a day without any luck. I'm using Ruby on Rails and Koala.

If I try to connect as follows:

graph = Koala::Facebook::API.new(User_Token)

Then there is no problem. (Where user token was obtained from https://developers.facebook.com/tools/access_token/)

The problem is that the user token expires. I am aware that there is a way to extend the app User Token, but I would rather not resort to this.

Rather, I am trying to authenticate my app to obtain an APP ACCESS TOKEN which I can use in lieu of the User Token (as per https://developers.facebook.com/docs/facebook-login/access-tokens#apptokens. Please note this refers to the App Access Token, not the App Token which was referred to in the first link).

In order to obtain the App Access Token, I have followed a tutorial and provided this code in my controller:

id = <my app id>
secret = <my app secret>
callbackUrl = "http://localhost:3000/events/appcallback"
@ouath = Koala::Facebook::OAuth.new(id, secret, callbackUrl)
redirect_to @oauth.url_for_oauth_code()

in my routes.rb I have:

match "events/appcallback" =>  "events#appCalledBack", via: :get

This is purely to test that the callback worked.

My intention was then to do something like:

App_Access_Token = @oauth.get_access_token(params[:code])

But instead I get an error: NoMethodError in EventsController#index undefined method `url_for_oauth_code' for nil:NilClass

Please note that I am not interested in obtaining an access token for a user; I want one for my app, so that I can connect to the api a la:

graph = Koala::Facebook::API.new(App_Access_Token)

Any help would be greatly, greatly appreciated.

orrymr
  • 2,264
  • 4
  • 21
  • 29

1 Answers1

0

So it seems that your route is wrong, since it goes to EventsController#index. Can you post some logs and the relevant routes?

PoloniculMov
  • 219
  • 3
  • 9