2013-04-18 83 views
0

Iam獲取像名稱,位置等所有的朋友信息作爲響應的圖形對象,但是當我想從JSON獲取位置時,它給我的位置沒有任何價值。請幫助我並告訴我IAM做錯了什麼地方?獲取沒有位置的值?

Bundle required = new Bundle(); 
       required.putString("fields", "id,name,picture,location,locale,gender,email"); 
       Request req = new Request(session, "me/friends", required,HttpMethod.GET, 
         new Callback() { 

          @Override 
          public void onCompleted(Response response){ 
           GraphObject is=response.getGraphObject(); 
           // Log.w("FriendsList", is.toString()); 
           String location=""; 
             if (is != null) { 
              JSONObject jsonObject = is.getInnerJSONObject(); 

              try { 

               JSONArray myfriendlist=new JSONArray(); 
              JSONArray array = jsonObject.getJSONArray("data"); 
              for (int i = 0; i < array.length(); i++) { 

               JSONObject object = (JSONObject) array.get(i); 
               JSONObject friendlist = new JSONObject(); 
               JSONObject keyfriendlist = new JSONObject(); 

              JSONArray loc = jsonObject.getJSONArray("location"); 
              for(int j=0;j<loc.length();j++){ 
             location=object.get("id").toString(); 
              if(location==null||location==""||location=="null") 
              { 
               continue; 
              }} 

logcat的

04-18 18:48:37.360: W/System.err(28862): org.json.JSONException: No value for location 
04-18 18:48:37.365: W/System.err(28862): at org.json.JSONObject.get(JSONObject.java:354) 
04-18 18:48:37.365: W/System.err(28862): at org.json.JSONObject.getJSONArray(JSONObject.java:544) 
04-18 18:48:37.365: W/System.err(28862): at com.example.socialize_us.MainFragment$2.onCompleted(MainFragment.java:106) 
04-18 18:48:37.365: W/System.err(28862): at com.facebook.Request$4.run(Request.java:1240) 
04-18 18:48:37.365: W/System.err(28862): at android.os.Handler.handleCallback(Handler.java:605) 
04-18 18:48:37.365: W/System.err(28862): at android.os.Handler.dispatchMessage(Handler.java:92) 
04-18 18:48:37.365: W/System.err(28862): at android.os.Looper.loop(Looper.java:137) 
04-18 18:48:37.365: W/System.err(28862): at android.app.ActivityThread.main(ActivityThread.java:4666) 
04-18 18:48:37.365: W/System.err(28862): at java.lang.reflect.Method.invokeNative(Native Method) 
04-18 18:48:37.366: W/System.err(28862): at java.lang.reflect.Method.invoke(Method.java:511) 
+0

你能否更新與你從Facebook獲得什麼權限的問題? –

+0

請問您是否可以用刪除個人信息後從Facebook獲得的樣本回復更新您的問題? –

+0

location是一個JSONObject而不是JSONArray。 –

回答

0
org.json.JSONException: No value for location 

此異常告訴JSON找不到location TAG

請確保您的JSON字符串數組有它通過location TAG conatined

JSONArray loc = jsonObject.getJSONArray("location") 
0

「我/朋友」的圖API僅返回Friend's Name和fbid。但是您正在嘗試閱讀其他屬性,這些屬性在此調用中將不可用。 這將返回類似:

{ "name": "Friend's NAme", "id": "545981122" },

檢查這個位置Facebook Graph Api for me/friends

爲了得到你需要從上面的電話讓他的ID,然後得到的是一個朋友的介紹一個朋友的位置:

我/朋友/ 545981122

其中545981122是朋友的ID。

希望它有幫助。

乾杯!

+0

@Saad:當您想查看單個用戶的詳細信息時,您可以創建一個圖形API調用,如:「https:// graph.facebook.com/570074679」,其中「570074679」是fbid。 ,它會回報你是這樣的: '{ 「ID」: 「570074679」, 「名」: 「塔希爾·馬哈茂德」, 「FIRST_NAME」: 「塔希爾」, 「姓氏」: 「馬哈茂德·」 「link」:「http://www.facebook.com/eng.tahir.mehmood」, 「username」:「eng.tahir.mehmood」, 「hometown」:{ 「id」:「110713778953693」 , 「名」: 「巴基斯坦卡拉奇」 }, 「位置」:{ 「ID」: 「110713778953693」, 「名」: 「巴基斯坦卡拉奇」 }' 你可以在這裏看到的位置。 –

+0

@ Tahir Mehmood是啊iam得到這個,但如何得到這個位置「:{」id「:」110713778953693「,」name「:」巴基斯坦卡拉奇「} iam沒有位置值 – Saad

+0

該人應該設置他的位置個人資料。 –