2011-10-08 27 views
6

trong theres facebook FQL mã nàyLàm thế nào tôi có thể làm facebook FQL mẻ trong 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 

nó giả sử để được gửi đi với json nhưng tôi thực sự không hiểu làm thế nào để làm điều này bất kỳ sự giúp đỡ?

cảm ơn

+0

Bạn có thể chính xác hơn trong câu hỏi của mình không? bạn đã thử cái gì, bạn đã mong đợi điều gì và kết quả của bạn là gì? bạn đã thử lệnh trên chưa? nó đã thất bại? bạn đã cài đặt curl chưa? nó có phản ứng không? Bạn đã nhận được gì? bạn thấy thông báo lỗi nào? –

Trả lời

3

Bạn có thể sử dụng đơn giản BatchFB api của nó rất mạnh mẽ và dễ dàng, bạn không phải đối phó sẽ tất cả các công cụ và nó sử dụng FQL ví dụ để có được tất cả bạn bè của bạn

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

và được sắp xếp theo số

2

Tôi tin rằng câu hỏi của bạn là cách thực hiện yêu cầu hàng loạt bằng cách sử dụng API đồ thị Facebook. Đối với điều này, bạn phải đưa ra một yêu cầu POST để

"https://graph.facebook.com" 

và dữ liệu gửi lên được gửi nên

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

trong trường hợp của bạn [@accesstoken phải được thay thế bằng giá trị thẻ truy cập của bạn].

Yêu cầu này sẽ trả lại chi tiết của chủ sở hữu mã thông báo truy cập (thường là người dùng đã đăng nhập hiện tại) và danh sách 50 bạn bè trên facebook (chứa trường id và tên) của người dùng cùng với tiêu đề trang (có thể bỏ qua)).

Tôi không chắc chắn bạn có nghĩa là java hay Javascript. Xin được cụ thể về nó.

Tôi là người lập trình C# về cơ bản. Sẽ cung cấp cho bạn một mã để thực hiện yêu cầu trên trong C# tại đây.

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

Ở đây biến số dữ liệu sẽ chứa kết quả.

1

Salah, đây là ví dụ tôi sử dụng làm tài liệu tham khảo, tôi xin lỗi mặc dù tôi không nhớ nơi tôi tìm thấy.

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); 
      } 
     } 
    } 
}); 
Các vấn đề liên quan