2016-08-16 8 views
4

android twitter successfull loginの後にすべてのユーザー情報を取得します。
twiiterログインのために私はファブリックを使用します。ここに私のコードです。 onCreateでAndroidService.verifyCredentials()のファブリックを使用したtwitterログインは、新しいコールバックを受け取りません()

()

twitterLoginButton = (TwitterLoginButton) findViewById(R.id.twitterLogin); 

twitterLoginButton.setCallback(new Callback<TwitterSession>() { 
     @Override 
     public void success(Result<TwitterSession> result) { 
      //If login succeeds passing the Calling the login method and passing Result object 
      twitter_login(result); 
     } 

     @Override 
     public void failure(TwitterException exception) { 
      //If failure occurs while login handle it here 
      Log.d("TwitterKit", "Login with Twitter failure", exception); 
     } 
    }); 

と機能twitter_login())(virifyCredentialsで

public void twitter_login(Result<TwitterSession> result) { 

    //Creating a twitter session with result's data 
    TwitterSession session = result.data; 

    //Getting the username from session 
    final String username = session.getUserName(); 

    //This code will fetch the profile image URL 
    //Getting the account service of the user logged in 

    /*AccountService ac = Twitter.getApiClient(result.data).getAccountService(); 
    ac.verifyCredentials(true, true);*/ 

    Twitter.getApiClient(session) 
      .getAccountService() 
      .verifyCredentials(true, false, new Callback<User>() { 

       @Override 
       public void failure(TwitterException e) { 
        //If any error occurs handle it here 
       } 

       @Override 
       public void success(Result<User> userResult) { 

        String imageUrl = userResult.data.profileImageUrl; 
        String email = userResult.data.email; 
        String Name = userResult.data.name; 
        long userid = userResult.data.id; 
        String username = userResult.data.screenName; 

        System.out.println(imageUrl); 
        System.out.println("EMAIL:" + email); 
        System.out.println("Name:" + Name); 
        System.out.println("ID:" + userid); 
        System.out.println("Username:" + username); 
       } 
      }); 
} 

あり、それはエラー新しいコールバック(thros)を適用することができません。
この方法の使い方を教えてください。
ありがとうございます。

+0

新しいTwitterのSDKは私に頭痛を与えます。 –

答えて

7

私は試みを行うことによって解決策を見つけた:

public void success(Result<TwitterSession> result) 
{ 
    TwitterSession session = result.data; 
    Twitter   twitter = Twitter.getInstance(); 
    TwitterApiClient api  = twitter.core.getApiClient(session); 
    AccountService service = api.getAccountService(); 
    Call<User>  user = service.verifyCredentials(true, true); 

    user.enqueue(new Callback<User>() 
    { 
     @Override 
     public void success(Result<User> userResult) 
     { 
      String name = userResult.data.name; 
      String email = userResult.data.email; 

      // _normal (48x48px) | _bigger (73x73px) | _mini (24x24px) 
      String photoUrlNormalSize = userResult.data.profileImageUrl; 
      String photoUrlBiggerSize = userResult.data.profileImageUrl.replace("_normal", "_bigger"); 
      String photoUrlMiniSize  = userResult.data.profileImageUrl.replace("_normal", "_mini"); 
      String photoUrlOriginalSize = userResult.data.profileImageUrl.replace("_normal", ""); 
     } 

     @Override 
     public void failure(TwitterException exc) 
     { 
      Log.d("TwitterKit", "Verify Credentials Failure", exc); 
     } 
    }); 
} 
+0

このソリューションをありがとうございました@ Nevada750 – siva

+0

私の弟を救ってください –

関連する問題