2

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

Victor Yee
  • 151
  • 1
  • 14

3 Answers3

5

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.

MatayoshiMariano
  • 2,026
  • 19
  • 23
1

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

andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • Do you mean try like this - friends: @graph.get_connections("me?", "fields=birthday") ? For some reason it is returning me with id, birthday,first_name, last_name, etc etc – Victor Yee Jan 15 '16 at 11:03
  • If I remove the '?' from 'me?' it will give me type: OAuthException, code: 2500, message: Unknown path components: /fields=birthday [HTTP 400] – Victor Yee Jan 15 '16 at 11:05
  • well, then use the solution that works, and not the one that does not work ;) – andyrandy Jan 15 '16 at 11:39
  • What I meant was if I were to do just birthday @graph.get_connections("me?", "fields=birthday") it gives me birthday PLUS id, first_name, etc. I changed it to @graph.get_connections("", "me?fields=birthday") and it returns birthday PLUS the user ID., lol – Victor Yee Jan 15 '16 at 11:49
  • ok, that is weird. in general, you always need to define every field you want to get returned, by default you only get id and name. – andyrandy Jan 15 '16 at 11:53
1

I think this should do it!

rest = Koala::Facebook::API.new(access_token)
rest.get_object("me?fields=birthday")
Philip
  • 6,827
  • 13
  • 75
  • 104