2015-07-05 103 views
2

我有一個標籤樹的朋友列表有問題,這是我的代碼,與舊的sdk工作得很好。在facebook上獲得taggable朋友sdk 4.0+

 public void getTaggableFriends(){ 
     Session activeSession = Session.getActiveSession(); 
     if(activeSession.getState().isOpened()){ 
     new Request(
       activeSession, 
       "/me/taggable_friends", 
       null, 
       HttpMethod.GET, 
       new Request.Callback() { 
        public void onCompleted(Response response) { 

         GraphObject graphObject = response.getGraphObject(); 
         if (graphObject != null) { 
          JSONObject jsonObject = graphObject.getInnerJSONObject(); 
          String taggableFriendsJson = jsonObject.toString(); 
          Gson gson = new Gson(); 
          TaggableFriendsWrapper taggableFriendsWrapper= gson.fromJson(taggableFriendsJson, TaggableFriendsWrapper.class); 
          ArrayList<TaggableFriends> invitableFriends = new ArrayList<TaggableFriends>(); 
          invitableFriends = taggableFriendsWrapper.getData(); 
          int i; 
          for(i = 0; i < invitableFriends.size(); i++) 
          { 
           try 
           { 
           MainActivity.myMenu.add(invitableFriends.get(i).getName()); 
           } 
           catch(Exception e){} 
          } 
          MainActivity.myMenu.add("Tot: " + i); 
         }else { 

         } 
         //response.get 

        } 
       } 
      ).executeAsync(); 
     } 
    } 

到了這一步,我該如何適應SDK 4.0?還是有其他的方式來做到這一點?我不知道從哪裏開始,在此先感謝。

回答

1

你可以簡單地將其更改爲

if(AccessToken.getCurrentAccessToken() != null) 
{ 
    GraphRequest graphRequest = GraphRequest.newGraphPathRequest(
      AccessToken.getCurrentAccessToken(), 
      "me/taggable_friends", 
      new GraphRequest.Callback() 
      { 
       @Override 
       public void onCompleted(GraphResponse graphResponse) 
       { 
        //Your code 

        if(graphResponse != null) 
         { 
          JSONObject jsonObject = graphResponse.getJSONObject(); 
          String taggableFriendsJson = jsonObject.toString(); 
          Gson gson = new Gson(); 
          TaggableFriendsWrapper taggableFriendsWrapper= gson.fromJson(taggableFriendsJson, TaggableFriendsWrapper.class); 
          ArrayList<TaggableFriends> invitableFriends = new ArrayList<TaggableFriends>(); 
          invitableFriends = taggableFriendsWrapper.getData(); 
          int i; 
          for(i = 0; i < invitableFriends.size(); i++) 
          { 
           try 
           { 
            MainActivity.myMenu.add(invitableFriends.get(i).getName()); 
           } 
           catch(Exception e){} 
          } 
          MainActivity.myMenu.add("Tot: " + i); 
         }else { 

         } 
         //response.get 

       } 
      } 
     ); 

     Bundle parameters = new Bundle(); 
     parameters.putInt("limit", 5000); //5000 is maximum number of friends you can have on Facebook 

     graphRequest.setParameters(parameters); 
     graphRequest.executeAsync(); 
    } 
+0

非常感謝!只有一個前所未有的問題回到了我的朋友身邊,現在只有25歲? GraphAPI有什麼變化嗎? –

+1

是的,它被限制爲25,給我一分鐘,我會改變代碼,以解決該問題:) –

+1

完成後,你應該現在所有的朋友:) –