Skip to content

Results from "comments" request are sometimes Arrays instead of Hashes #13

@bradical

Description

@bradical

Hi, I've run into a strange issue that could be related to Facebook's Graph API or could be related to this gem.

Basically, when I make a request for a post's comments, sometimes I get a Hash and other times I seem to get an array. The code that makes the request and processes the comment is below.

The reason I know this is what's happening is that I'm getting an error on this line: from = comment["from"] about how I can't convert String to Fixnum so I'm assuming that the comment object is an indexed Array at that point.

You can see that I've added some code that will skip comments that aren't Hashes to avoid this problem but I'm curious about why it might be happening.

Thanks!

def read_feed
  client.object("#{self.facebook_page_id}/feed").each do |item|
    next unless item.is_a?(Hash)
    message = do_something_with_feed_item_hash(item)

    client.object("#{item["id"]}/comments").each do |comment|
      next unless comment.is_a?(Hash)
      do_something_with_comment_hash(comment)
    end
  end
end

def do_something_with_comment_hash(comment)
  from = comment["from"]
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions