nov / fb_graph

This gem doesn't support FB Graph API v2.0+. Please use fb_graph2 gem instead.
MIT License
1.04k stars 191 forks source link

NoMethodError: undefined method `each' for nil:NilClass in post.rb #327

Closed giovannelli closed 11 years ago

giovannelli commented 11 years ago

Hi, i'm getting undefined method each for some facebook posts, seems that "message_tag" at line 44 in post.rb is nil.

Try this: _FbGraph::Post.new("10151464423983204_26704105", :access_token => a_validtoken).fetch

You get: NoMethodError: undefined method `each' for nil:NilClass

I've solved with this:

message_tag.each do |_message_tag_|
  @message_tags << TaggedObject.new(_message_tag_[:id], _message_tag_)
end if !message_tag.nil?

or

message_tag.compact.each do |_message_tag_|
  @message_tags << TaggedObject.new(_message_tag_[:id], _message_tag_)
end

The same problem on story_tags i think, even if i've not find till now a story with this issue.

Cheers

tmlee commented 11 years ago

The post you are requesting returns a message tag of this format :- "message_tags": [ { "id": "38919051253", "name": "O2", "type": "page", "offset": 117, "length": 2 } ]

FBGraph is expecting it to be in "message_tags": [ "0": { "id": "38919051253", "name": "O2", "type": "page", "offset": 117, "length": 2 } ]

Any idea what's the reason that this response do not return a key value hash?

nov commented 11 years ago

The latter is the expected format of message_tags in post object.

object containing fields whose names are the indexes to where objects are mentioned in the message field; each field in turn is an array containing an object with id, name, offset, and length fields, where length is the length, within the message field, of the object mentioned

https://developers.facebook.com/docs/reference/api/post/

However, 10151464423983204_26704105111 is a comment object, not a post. And now I realized FB includes message_tags in comments too.

ps. You can see FB Graph API object type by putting metadata=true in query. e.g.) https://graph.facebook.com/10151464423983204_26704105?metadata=true

ps2. message_tags in comments seems undocumented attribute yet. If you need them, we can add them, but if not, let's ignore them for now. https://developers.facebook.com/docs/reference/api/Comment/

giovannelli commented 11 years ago

Yes it includes message_tags in a different format.

Many tnx

Duccio

tmlee commented 11 years ago

Since its a comment, you can probably use FbGraph::Comment.new(..).fetch That will not raise any error, that's because its not mapping the message_tags directly Anyhow you can access it via comment.raw_attributes["message_tags"]

giovannelli commented 11 years ago

Ok tnx, i'll use FbGraph::Comment instead of FbGraph::Post and i access message_tags using raw_attributes. Cheers