@@ -21,6 +21,7 @@ def created_time
21
21
22
22
def self . new_connection
23
23
@graph = Koala ::Facebook ::API . new ( ENV [ 'FACEBOOK_ACCESS_TOKEN' ] )
24
+ Koala . config . api_version = "v2.9"
24
25
end
25
26
26
27
def self . get ( meth , username , amount )
@@ -34,7 +35,7 @@ def self.get(meth, username, amount)
34
35
end
35
36
36
37
def self . connections ( username , count )
37
- @graph . get_connections ( username , 'posts' , { limit : count } )
38
+ @graph . get_connections ( username , 'posts' , { limit : count , fields : [ 'object_id' , 'message' , 'message_tags' , 'id' , 'type' , 'from' , 'picture' , 'link' , 'created_time' , 'status_type' , 'caption' , 'name' , 'description' ] } )
38
39
end
39
40
40
41
def self . get_object ( object )
@@ -76,7 +77,7 @@ def has_photo?
76
77
end
77
78
78
79
def photo
79
- data = FB . get_object ( @post [ 'object_id' ] )
80
+ data = FB . get_object ( @post [ 'object_id' ] + '?fields=width,height,source' )
80
81
src_full = FB . get_picture_data ( @post [ 'object_id' ] , 'normal' ) [ 'data' ] [ 'url' ] if @post [ 'type' ] == 'photo'
81
82
src_full = FB . get_object ( @post [ 'object_id' ] +'?fields=cover' ) [ 'cover' ] [ 'source' ] if @post [ 'type' ] == 'event'
82
83
@@ -104,7 +105,7 @@ def video
104
105
video [ 'link' ] = @post [ 'link' ]
105
106
video [ 'id' ] = /\/ videos\/ (?:t\. \d +\/ )?(\d +)/i . match ( @post [ 'link' ] ) [ 1 ]
106
107
107
- picture_formats = FB . get_object ( video [ 'id' ] ) [ 'format' ]
108
+ picture_formats = FB . get_object ( video [ 'id' ] + '?fields=format' ) [ 'format' ]
108
109
i_avg = ( picture_formats . length . to_f /2 ) . round # get the average quality
109
110
110
111
video [ 'picture' ] = picture_formats [ i_avg -1 ] [ 'picture' ]
@@ -162,20 +163,20 @@ def ext_quote_picture
162
163
def ext_quote
163
164
quote = Hash . new
164
165
quote [ 'link' ] = @post [ 'link' ]
165
- quote [ 'picture' ] = has_ext_quote_picture? ? ext_quote_picture : get_url_best_picture ( quote [ 'link' ] )
166
+ quote [ 'picture' ] = get_url_best_picture ( quote [ 'link' ] )
166
167
quote [ 'source' ] = @post [ 'caption' ]
167
168
quote [ 'title' ] = @post [ 'name' ]
168
169
quote [ 'description' ] = @post [ 'description' ]
169
170
170
171
return quote
171
172
end
172
173
173
- # Message
174
-
175
174
def has_message_tags?
176
175
@post . has_key? ( 'message_tags' )
177
176
end
178
177
178
+ # Message
179
+
179
180
def has_message?
180
181
@post . has_key? ( 'message' )
181
182
end
@@ -187,10 +188,8 @@ def parse_message(text="")
187
188
text = text . gsub ( /\# ([a-z0-9âãäåæçèéêëìíîïðñòóôõøùúûüýþÿı_-]+)/i , '<a class="hashtag" href="https://www.facebook.com/hashtag/\1">#\1</a>' )
188
189
# Page, Group, user
189
190
if has_message_tags?
190
- @post [ 'message_tags' ] . each do |k , v |
191
- v . each do |h |
192
- text = text . gsub ( /\s (#{ h [ "name" ] } )\s / , " <a class='mention' href='https://www.facebook.com/#{ h [ "id" ] } '>@#{ h [ "name" ] } </a> " )
193
- end
191
+ @post [ 'message_tags' ] . each do |tag |
192
+ text = text . gsub ( /\s (#{ tag [ "name" ] } )\s / , " <a class='mention' href='https://www.facebook.com/#{ tag [ "id" ] } '>@#{ tag [ "name" ] } </a> " )
194
193
end
195
194
end
196
195
@@ -200,7 +199,7 @@ def parse_message(text="")
200
199
# Infos
201
200
202
201
def user_info
203
- username = FB . get_object ( @post [ 'from' ] [ 'id' ] ) [ 'username' ]
202
+ username = FB . get_object ( @post [ 'from' ] [ 'id' ] + '?fields=username' ) [ 'username' ]
204
203
picture = FB . get_picture_data ( @post [ 'from' ] [ 'id' ] , 'normal' )
205
204
206
205
user = Hash . new
0 commit comments