2013-02-07 35 views
1

我是一個新手到Android SDK的Facebook SDK開發,我正在做一個圖形API查詢來檢索我的Facebook個人資料的FriendList信息。無法獲取FriendList信息使用最新的Facebook SDK3.0

我正在使用最新的sdk。有關於SOF w.r.t old sdk的解決方案,但我想使用最新的套件來實現它。

/me/friends的查詢會返回一個JSON響應,其中nameIDs的朋友很容易解析。但是當我試圖通過查詢/me/friends/?fields=birthday來獲得生日等額外信息時,我收到了無效的回覆。

我也在onCreateView方法中設置了friends_birthday的權限。

這裏是我的代碼:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    View view = inflater.inflate(R.layout.activity_main, container, false); 
    LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton); 
    authButton.setFragment(this); 
    authButton.setReadPermissions(Arrays.asList("user_location", "user_birthday", "user_likes","read_friendlists","friends_birthday")); /*setting permissions*/ 
    userInfoTextView = (TextView) view.findViewById(R.id.userInfoTextView); 
    return view; 
} 


public void onResume() { 
    super.onResume(); 
    Session session = Session.getActiveSession(); 
    if (session != null && 
      (session.isOpened() || session.isClosed())) { 
     onSessionStateChange(session, session.getState(), null); 
    } 
    uiHelper.onResume(); 
} 


private void onSessionStateChange(Session session, SessionState state, Exception exception) { 
    if (state.isOpened()) { 
     Log.i(TAG, "Logged in..."); 
     userInfoTextView.setVisibility(View.VISIBLE); 
     Settings.addLoggingBehavior(LoggingBehavior.REQUESTS); 
     String graphpath="/me/friends?fields=name,birthday"; 

     Request.executeGraphPathRequestAsync(session, graphpath, new Request.Callback(){ 

      @Override 
      public void onCompleted(Response response) { 
       try { 
         userInfoTextView.setText(buildUserInfoDisplay(response)); 
       } catch (JSONException e) { 

        Log.d(TAG,"JSON exception"); 
        e.printStackTrace(); 
       } 

      } 



     }); 
    } 


else if (state.isClosed()) { 
     Log.i(TAG, "Logged out..."); 
     userInfoTextView.setVisibility(View.INVISIBLE); 
    } 
} 



private String buildUserInfoDisplay(Response response) throws JSONException { 

     if(response.getError()!=null) 
     Log.d(TAG, "null reponse returned..."); 
    GraphObject go = response.getGraphObject(); 
    JSONObject jso = go.getInnerJSONObject(); 
     JSONArray arr = jso.getJSONArray("data"); 
     JSONObject json_obj = arr.getJSONObject(2); /*getting the third friend from the list*/ 
     String birthday = json_obj.getString("birthday"); 
     return birthday; 
} 

回答

0

並非所有的朋友們的生日條目。所以你需要在直接閱讀之前檢查是否有「生日」標籤。你可以在Graph Explorer中測試結果

https://developers.facebook.com/tools/explorer?method=GET&path=me%2Ffriends%3Ffields%3Dname%2Cid%2Cbirthday

+0

是的我已經檢查過了。我正試圖從那位生日記錄的朋友那裏查詢生日信息。基本上,當我說「/ me/friends /?fields = birthday」時,我得到的是一個空的JSON響應,既沒有ID,名稱也沒有任何東西。至少與我用來獲取姓名和身份證的「我/朋友」。任何與權限或訪問令牌有關的事情? – user2043682

+0

是檢查您在「獲取訪問令牌」按鈕上設置的權限。你需要請求像friends_birthday這樣的其他朋友權限 –

相關問題