Gem Koala Facebook API get_object request

天大地大妈咪最大 提交于 2019-12-22 17:11:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!