11note
2- description : " Summary description for {FACEBOOK_API}."
3- date : " $Date$"
4- revision : " $Revision$"
2+ description : " [
3+ Facebook API Interface: specify how to read and write Facebook data.
4+ ]"
5+ date : " $Date: 2018-09-06 13:07:18 -0300 (ju. 06 de sep. de 2018) $"
6+ revision : " $Revision: 102137 $"
7+ EIS : " name=Facebook Graph API" , " src=http://developers.facebook.com/docs/api" , " protocol=uri"
58
69class
710 FACEBOOK_API
@@ -124,9 +127,53 @@ feature -- Facebook: Get User
124127 end
125128 end
126129
130+ user_likes (a_path : STRING ; a_params : detachable FB_PAGE_PARAMETER ): detachable STRING
131+ do
132+ if
133+ a_params /= Void and then
134+ attached a_params .parameters as l_parameters
135+ then
136+ api_get_call (facebook_url (a_path , l_parameters ), Void )
137+ else
138+ if a_path .starts_with (" https" ) then
139+ api_get_call (a_path , Void )
140+ else
141+ api_get_call (facebook_url (a_path , Void ), Void )
142+ end
143+ end
144+ if
145+ attached last_response as l_response and then
146+ attached l_response .body as l_body
147+ then
148+ Result := l_body
149+ end
150+ end
151+
152+ user_groups (a_path : STRING ; a_params : detachable FB_GROUP_PARAMETER ): detachable STRING
153+ do
154+ if
155+ attached a_params and then
156+ attached a_params .parameters as l_parameters
157+ then
158+ api_get_call (facebook_url (a_path , l_parameters ), Void )
159+ else
160+ if a_path .starts_with (" https" ) then
161+ api_get_call (a_path , Void )
162+ else
163+ api_get_call (facebook_url (a_path , Void ), Void )
164+ end
165+ end
166+ if
167+ attached last_response as l_response and then
168+ attached l_response .body as l_body
169+ then
170+ Result := l_body
171+ end
172+ end
173+
127174feature -- Feeds: publish, delete, update
128175
129- user_feed_publish (a_user_id : STRING ; a_params : detachable FB_USER_FEED_PUBLISHING ): detachable STRING
176+ publish_on_user_feed (a_user_id : STRING ; a_params : detachable FB_USER_FEED_PUBLISHING ): detachable STRING
130177 do
131178 api_post_call (facebook_url (a_user_id , Void ), a_params , Void )
132179 if
@@ -148,11 +195,23 @@ feature -- Feeds: publish, delete, update
148195 end
149196 end
150197
151- user_feed_publish_photo (a_user_id : STRING ; a_photo : PATH ): detachable STRING
152- local
153- l_file : RAW_FILE
198+ publish_photo_on_user_feed (a_user_id : STRING ; a_photo : PATH ; a_params : detachable FB_USER_FEED_PUBLISHING ): detachable STRING
154199 do
155- api_post_call (facebook_url (a_user_id , Void ), Void , [a_photo , " multipart/form-data; boundary=%" attachment boundary %" " ])
200+ api_post_call (facebook_url (a_user_id , Void ), a_params , [a_photo , " multipart/form-data" ])
201+
202+ if
203+ attached last_response as l_response and then
204+ attached l_response .body as l_body
205+ then
206+ Result := l_body
207+ end
208+ end
209+
210+
211+ publish_video_on_user_feed (a_user_id : STRING ; a_video : PATH ; a_params : detachable FB_VIDEO_PUBLISHING ): detachable STRING
212+ do
213+ api_post_call (facebook_video_url (a_user_id , Void ), a_params , [a_video , " multipart/form-data" ])
214+
156215 if
157216 attached last_response as l_response and then
158217 attached l_response .body as l_body
@@ -262,7 +321,7 @@ feature {NONE} -- Implementation
262321 EIS :" name=access token" , " src=https://developers.facebook.com/docs/facebook-login/access-tokens" , " protocol=uri"
263322 local
264323 request : OAUTH_REQUEST
265- l_access_token , request_token : detachable OAUTH_TOKEN
324+ l_access_token : detachable OAUTH_TOKEN
266325 api_service : OAUTH_ 20 _SERVICE
267326 do
268327 -- Initialization
@@ -295,7 +354,7 @@ feature {NONE} -- Implementation
295354 end
296355
297356 facebook_url (a_query : STRING ; a_params : detachable STRING ): STRING
298- -- Twitter url for `a_query' and `a_parameters'
357+ -- Facebook url for `a_query' and `a_parameters'
299358 require
300359 a_query_attached : a_query /= Void
301360 do
@@ -308,6 +367,20 @@ feature {NONE} -- Implementation
308367 Result_attached : Result /= Void
309368 end
310369
370+ facebook_video_url (a_query : STRING ; a_params : detachable STRING ): STRING
371+ -- Facebook url for `a_query' and `a_parameters'
372+ require
373+ a_query_attached : a_query /= Void
374+ do
375+ Result := " https://graph-video.facebook.com/v2.9/" + a_query
376+ if attached a_params then
377+ Result .append_character ('?')
378+ Result .append (a_params )
379+ end
380+ ensure
381+ Result_attached : Result /= Void
382+ end
383+
311384 url (a_base_url : STRING ; a_parameters : detachable ARRAY [detachable TUPLE [name : STRING ; value : STRING ]]): STRING
312385 -- url for `a_base_url' and `a_parameters'
313386 require
@@ -355,16 +428,13 @@ feature {NONE} -- Implementation
355428 end
356429
357430 add_parameters (a_method : STRING ; request :OAUTH_REQUEST ; a_params : detachable STRING_TABLE [STRING ])
431+ -- add parameters 'a_params' (with key, value) to the oauth request 'request'.
432+ -- | at the moment all params are added to the query_string.
358433 do
359- if a_method .is_case_insensitive_equal_general (" GET" ) or else a_method .is_case_insensitive_equal_general (" DELETE" ) then
360- add_query_string (request , a_params )
361- else
362- check is_post : a_method .is_case_insensitive_equal_general (" POST" ) end
363- add_body_parameters (request , a_params )
364- end
434+ add_query_parameters (request , a_params )
365435 end
366436
367- add_query_string (request :OAUTH_REQUEST ; a_params : detachable STRING_TABLE [STRING ])
437+ add_query_parameters (request :OAUTH_REQUEST ; a_params : detachable STRING_TABLE [STRING ])
368438 do
369439 if attached a_params then
370440 across a_params as ic
@@ -393,9 +463,8 @@ feature {NONE} -- Implementation
393463 create l_raw_file .make_open_read (l_upload_data .file_name .absolute_path .name )
394464 if l_raw_file .exists then
395465 request .add_header (" Content-Type" , l_upload_data .content_type )
396- request .add_header (" Content-Disposition" , " form-data; filename=%" + l_upload_data .file_name .name %" " )
397- request .add_header (" Content-Length" , l_raw_file .count .out )
398466 request .set_upload_filename (l_upload_data .file_name .absolute_path .name )
467+ request .add_form_parameter (" source" , l_upload_data .file_name .name .as_string_ 32 )
399468 end
400469 end
401470 end
0 commit comments