2

我正在尝试通过我的应用程序获取我所有朋友的家乡位置和当前位置。我开始知道要获取位置,我必须设置权限并编写 FQL。我写了那个,并且 URL 变成了 My Graph API 格式
,但是当我使用这个链接来获取 json 时,我没有得到值。我尝试用空格替换 %20 并尝试过,但这也很有效。请告诉我出了什么问题。并告诉我应该使用哪个 URL。

我获取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();
            }
4

2 回答 2

0

我尝试用空格替换 %20 并尝试过,但这也很有效。

URL 编码一个值不仅仅是替换空格。还有其他字符也希望被它们的 %xy 表示替换——例如逗号。

以正确的方式对整个FQL 查询进行 URL 编码,它将起作用:

https://developers.facebook.com/tools/explorer?fql=SELECT+name%2C+uid%2C+current_location%2C+hometown_location+FROM+user+WHERE+uid+in+%28SELECT+uid2+FROM+friend+ WHERE+uid1+%3D+我%28%29%29

于 2012-09-22T12:35:54.550 回答
0

你也可以通过 Graph API 来做更简单的事情。

1)您需要具有权限的access_token;

To read Posts with location information, you need:
    user_photos or friends_photos for Photos
    user_status or friends_status for Posts (not including Photos)
    user_checkins or friends_checkins for Checkins only (excluding all other types of Posts)

2)然后调用这个

https://graph.facebook.com/search?type=checkin&access_token=

这将返回我(经过身份验证的用户)+朋友的 location_tagged 项目

于 2012-09-22T20:07:32.300 回答