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

Fetch images from a post + refactoring #366

Closed avokhmin closed 10 years ago

avokhmin commented 10 years ago

Fetches images from a post.

Example form FB graph:

   "images": [
      {
         "height": 688,
         "source": "https://scontent-a.xx.fbcdn.net/hphotos-xpa1/v/t1.0-9/10561773_10152440606793600_1776025110345181258_n.jpg?oh=4906f82b8953e685cf8162317ab38d87&oe=54405E40",
         "width": 957
      }, ...
    ]

How to reproduce:

[8] pry(main)> post = FbGraph::Post.new('10152440606793600', access_token: access_token).fetch
=> #<FbGraph::Post:0x007fe682be9e50 ...>
[9] pry(main)> post.images
NoMethodError: undefined method `images' for #<FbGraph::Post:0x007fe682be9e50>
[10] pry(main)> post.raw_attributes['images']
=> [{"height"=>688,
  "source"=>
   "https://scontent-a.xx.fbcdn.net/hphotos-xpa1/v/t1.0-9/10561773_10152440606793600_1776025110345181258_n.jpg?oh=4906f82b8953e685cf8162317ab38d87&oe=54405E40",
  "width"=>957}, ...]

So, I did small refactoring according to new style and added fetching of images

avokhmin commented 10 years ago

@nov, something wrong?

nov commented 10 years ago

Ah, sorry for my late response. BTW, 10152440606793600 seems Photo object, not Post. Why are you fetching the object as Post?

avokhmin commented 10 years ago

hm, good question... Looks like that absence of type field confused me. I will try to send metadata=1 and fetch type of object... Or maybe you know other way to detect type by id ?

Anyway, close this pull request

nov commented 10 years ago

I believe that metadata=1 is the best way when using developer console.

avokhmin commented 10 years ago

Thanks!