2011-10-08 12 views
6

in Theres facebook FQL questo codiceCome posso fare facebook FQL lotto in java

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 

si suppone per da inviare con JSON ma ho davvero non capisco come fare questo alcun aiuto?

grazie

+0

Puoi essere più preciso nella tua domanda? cosa hai provato, cosa ti aspettavi e qual è il risultato che hai ottenuto? hai provato il comando sopra? è fallito? hai arricciato installato? ha risposto? cosa hai preso? quale messaggio di errore vedi? –

risposta

3

È possibile utilizzare semplice la BatchFB api sua potente e facile, non dovete fare sarà tutto di queste cose e utilizzare il FQL per esempio per ottenere tutti i tuoi amici

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()) { 
      ....... 
     } 

e la sua partita in batch

2

Credo che la vostra domanda è come eseguire una richiesta in batch utilizzando Facebook Graph API. Per questo è necessario inviare una richiesta POST a

"https://graph.facebook.com" 

ei dati di post da inviare dovrebbe essere

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

nel tuo caso [@accesstoken deve essere sostituito con il vostro accesso valore simbolico].

Questa richiesta restituirà i dettagli del proprietario del token di accesso (normalmente l'utente attualmente connesso) e un elenco di 50 amici di Facebook (contiene campi ID e nome) dell'utente insieme alle intestazioni di pagina (può essere omesso).

io non sono sicuro se si intende Java o Javascript. Si prega di essere specifici su di esso.

Sono un programmatore C# in fondo. Fornirà un codice per eseguire la richiesta sopra in C# qui.

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'}]&[email protected]"); 
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(); 
      } 
     } 
    } 
} 

Qui i dati variabili conterrà il risultato.

1

Salah, qui è l'esempio che uso come riferimento, mi dispiace anche se non mi ricordo dove ho trovato.

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); 
      } 
     } 
    } 
});