问题
I'm trying to get user's info via Gem Koala Facebook API with below code
@graph = Koala::Facebook::API.new(auth_hash.credentials.token)
profile = @graph.get_object("me")
user.update(
url: auth_hash.extra.raw_info.id,
email: auth_hash.extra.raw_info.email,
friends: @graph.get_connections("me", "friends"),
birthday: @graph.get_object("me", "birthday")
)
friends: @graph.get_connections("me", "friends")
works perfectly fine, I will get a list of friends.
However birthday: @graph.get_object("me", "birthday")
will give me type: OAuthException, code: 2500, message: Unknown path components: /birthday [HTTP 400]
Things that returns arrays such as likes
, photos
works fine.
But strings such as last_name
, name
, first_name
will give me the same error.
What can I do to fix this? Is there something else I can enter instead of just birthday
回答1:
Although it is not very well documented, I read the code of the gem.
Here it explains how to do what you want.
You can do it like this:
Koala::Facebook::API.new(ACCESS_TOKEN).get_object(:me, { fields: [:birthday]})
This will return the birthday and the id of the user.
回答2:
birthday
is not an endpoint like friends
, it´s just a field in the user table. Same for name
, first_name
and last_name
:
/me?fields=name,birthday,first_name,last_name
I have no clue about Ruby and Koala, but i assume you can add the fields parameter as object - this is what it looks like in the docs:
@graph.get_object("me", {}, api_version: "v2.0")
Source: https://github.com/arsduo/koala
回答3:
I think this should do it!
rest = Koala::Facebook::API.new(access_token)
rest.get_object("me?fields=birthday")
来源:https://stackoverflow.com/questions/34808971/gem-koala-facebook-api-get-object-request