How can i make facebook batch fql in java

in facebook fql theres this code

https://developers.facebook.com/docs/reference/api/batch/ curl \ -F 'access_token=…' \ -F 'batch=[ \ {"method": "GET", "relative_url": "me"}, \ {"method": "GET", "relative_url": "me/friends?limit=50"} \ ]'\ https://graph.facebook.com 

it should be sent with json but i really don't understand how to do this any help?

thanks

+6
source share
3 answers

You can just use the BatchFB api its very powerful and light, you don’t have to deal with all these things and use fql for example to get all your friends

 Later<ArrayNode> friendsArrayList = this.Batcher.query("SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"); for (JsonNode friend : friendsArrayList.get()) { ....... } 

and its batch

+3
source

I believe your question is how to execute a batch request using the Facebook Graph API. To do this, you need to send a POST request for

 "https://graph.facebook.com" 

and the data sent must be

 "batch=[{'method': 'GET', 'relative_url': 'me'}, {'method': 'GET', 'relative_url': 'me/friends?limit=50'}]& access_token=@accesstoken " 

in your case [@accesstoken needs to be replaced with the access token value].

This request will return information about the owner of the access token (usually the current user in the system) and a list of 50 facebook friends (contains the id and name fields) of the user along with the page headers (can be omitted).

I'm not sure if you meant java or Javascript. Please be specific.

I am a C # programmer. Provides you the code to execute the above request in C # here.

 WebRequest webRequest = WebRequest.Create("https://graph.facebook.com"); webRequest.Method = "POST"; webRequest.ContentType = "application/x-www-form-UrlEncoded"; byte[] buffer = Encoding.UTF8.GetBytes("batch=[{'method': 'GET', 'relative_url': 'me'}, {'method': 'GET', 'relative_url': 'me/friends?limit=50'}]& access_token=@ACCESSTOKEN "); webRequest.ContentLength = buffer.Length; using (Stream stream = webRequest.GetRequestStream()) { stream.Write(buffer, 0, buffer.Length); using (WebResponse webResponse = webRequest.GetResponse()) { if (webResponse != null) { using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8)) { string data = streamReader.ReadToEnd(); } } } } 

Here the data strong> variable will contain the result.

+2
source

Salah, here is an example that I use as a reference, sorry, although I do not remember where I found.

 FB.api("/", "POST", { access_token:"MY_APPLICATION_ACCESS_TOKEN", batch:[ { "method":"GET", "name":"get-photos", "omit_response_on_success": true, "relative_url":"MY_ALBUM_ID/photos" }, { "method": "GET", "depends_on":"get-photos", "relative_url":"{result=get-photos:$.data[0].id}/likes" } ] }, function(response) { if (!response || response.error) { console.log(response.error_description); } else { /* Iterate through each Response */ for(var i=0,l=response.length; i<l; i++) { /* If we have set 'omit_response_on_success' to true in the Request, the Response value will be null, so continue to the next iteration */ if(response[i] === null) continue; /* Else we are expecting a Response Body Object in JSON, so decode this */ var responseBody = JSON.parse(response[i].body); /* If the Response Body includes an Error Object, handle the Error */ if(responseBody.error) { // do something useful here console.log(responseBody.error.message); } /* Else handle the data Object */ else { // do something useful here console.log(responseBody.data); } } } }); 
+1
source

Source: https://habr.com/ru/post/898885/


All Articles