2012-09-22 4 views
2

신청서로 모든 내 친구들의 집 위치 및 현재 위치를 찾으려고합니다. 나는 위치를 얻으려면 권한을 설정하고 FQL을 작성해야한다는 것을 알게되었습니다. 나는 그것을 썼고 URL은 My Graph API format
이되었지만 나는이 링크를 사용하여 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(); 
      } 
+0

인코딩 문자열의 location_tagged 항목을 반환이

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

를 호출하고 사용 그리고 수동으로 공간을 대신 % 20을 넣지 마십시오. – user

+0

URL은 이미 인코딩 된 형식입니다. 그러나 정보를 얻을 수 없습니다 .. 인코딩 된 형식과 URL 형식의 디코딩 된 형식을 모두 사용하여 시도했습니다. – Vaibs

+0

@Vaibs : Can 실행 코드를 게시하십시오. 이 FQL 쿼리? –

답변

0

당신은 또한 간단한 그래프 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) 다음 특수 문자가 당신이 응답을 얻을 것이다이 나 (인증 된 사용자) + 친구

+0

그래, 내가 그랬지 만, 특히 좋아하고 모든 .. 모든 친구에 대한 위치 (현재, 고향) 언급하지 ... 그리고 이것은 내 질문에 언급 한 링크가 다른 양식입니다 .. – Vaibs

+0

당신 말이 맞아! 고향 유형 정보는 사용자 프로필의 일부입니다. 내가 대답으로 준 예제는 '사용자가 시작한 위치 항목 (체크인, 태그, ...)'을 얻을 것입니다. – guleryuz

0

나는 공간으로 20 %를 교체 시도도하지만 너무 힘이 일 것을 시도했다.

URL 인코딩은 공백을 대체하는 것 이상입니다. % xy 표현으로 대체되기를 원하는 다른 문자가 있습니다 (예 : 쉼표).

URL 인코딩 올바른 방법으로 전체 FQL 쿼리, 그리고 그것을 작동합니다

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+me%28%29%29

관련 문제