我想通過我的應用程序獲取所有朋友的家鄉位置和當前位置。我開始知道,爲了獲得位置,我必須設置權限並編寫FQL。我寫了,網址變成 My Graph API format
但是當我使用這個鏈接來獲取JSON我沒有得到值。我試着用空格替換%20,然後嘗試着,即使如此,這個功能也很有用。 請告訴我出了什麼問題。並告訴我應該使用哪個網址。從Facebook獲取朋友的位置
我的代碼來獲得JSON值..:
String q = "https://developers.facebook.com/tools/explorer?fql=SELECT name, uid, current_location, hometown_location FROM user WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me())";
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(q);
try {
HttpEntity httpEntity = httpClient.execute(httpGet).getEntity();
if (httpEntity != null){
InputStream inputStream = httpEntity.getContent();
Reader in = new InputStreamReader(inputStream);
BufferedReader bufferedreader = new BufferedReader(in);
StringBuilder stringBuilder = new StringBuilder();
String stringReadLine = null;
while ((stringReadLine = bufferedreader.readLine()) != null) {
stringBuilder.append(stringReadLine + "\n");
}
qResult = stringBuilder.toString();
inputStream.close();
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Log.e("in try block", "in try block");
JSONObject JsonObject = new JSONObject(qResult);
JSONArray JsonArray = JsonObject.getJSONArray("data");
for(int i = 0;i < JsonArray.length(); i++){
Log.e("jksdhkvjsdlvm", "inside 1st for loop");
JSONObject fbInfo = JsonArray.getJSONObject(i);
name = fbInfo.getString("name");
uid = fbInfo.getString("uid");
current_location = JsonObject.getJSONArray("current_location");
for(int j = 0;j < current_location.length(); j++){
JSONObject currentInfo = current_location.getJSONObject(j);
c_city = currentInfo.getString("city");
c_state = currentInfo.getString("state");
c_country = currentInfo.getString("country");
Log.e("--->>>>", c_city);
}
hometown_location = JsonObject.getJSONArray("hometown_location");
for(int k = 0;k < hometown_location.length(); k++){
JSONObject homeInfo = hometown_location.getJSONObject(k);
h_city = homeInfo.getString("city");
h_state = homeInfo.getString("state");
h_country = homeInfo.getString("country");
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
編碼字符串的location_tagged項目,並使用它,你會得到響應,也有特殊字符並不手動把%20代替空間編碼它 – user
該網址已經在編碼形式..但我不能得到的信息..我試圖使用編碼格式以及解碼格式的網址.. – Vaibs
@Vaibs:你能在你運行的地方發佈代碼這個FQL查詢? –