Reputation: 222
I have an app which I want to be working only for people who like my page.
@show = 0
@graph = Koala::Facebook::API.new(access_token)
page = @graph.get_object("MyPage")
user_likes = @graph.get_connections("me", "likes")
user_likes.each do |like|
if like["id"] == page["id"]
# user likes my page
@show = 1
break
end
end
This is my code, my problem is how do I get the current user of my app, "me" gives me the user whose access_token I provide, so how do I get access token of the current user?
Upvotes: 1
Views: 1103
Reputation: 543
As far as I can tell, that code should be checking the current user's likes just like you want.
The access_token
provided to Koala::Facebook::API.new(access_token)
should be the access token for the current user of your application. The only way this would not be true is if you are using an application access token, which is really only needed to act on behalf of your application to do things like manage your real-time updates. In this case, you shouldn't be using it.
If you are using an application access token, you should instead be using the Facebook JavaScript SDK or OAuth redirect flow to authorize the current user and get their access token. You can then use this access token everywhere else in your app for the rest of the user's session. The Koala wiki has some info on both approaches to get the user's access token.
Upvotes: 1