xAuth Authentication for Twitter Share in Android?

后端 未结 1 1087
时光取名叫无心
时光取名叫无心 2021-01-24 19:18

I am working on the Twitter Authentication. The Basic Authentication will expire on August 16th onwards. So we have to use OAuth to use Twitter Authent

相关标签:
1条回答
  • 2021-01-24 19:37

    EDIT: In my code I did this:

    System.setProperty("twitter4j.oauth.consumerKey", "your token");
    System.setProperty("twitter4j.oauth.consumerSecret", "your token secret");
    
    Twitter twitter = new TwitterFactory().getInstance(login, password);
    
    AccessToken accessToken = twitter.getOAuthAccessToken();
    

    Then you must save your Token and Token secret from AccesToken

    if (mAccessToken != null) {
        if (mAccessToken.getToken() != null && mAccessToken.getTokenSecret() != null) {
            saveAccessToken(mAccessToken.getToken(), mAccessToken.getTokenSecret());
        }
    }
    

    When you want to use your Token you just do this:

    TwitterFactory factory = new TwitterFactory();
    Twitter twitter = factory.getInstance();
    twitter.setOAuthConsumer("[consumer key]", "[consumer secret]");
    AccessToken accessToken = loadAccessToken();
    twitter.setOAuthAccessToken(accessToken);
    
    0 讨论(0)
提交回复
热议问题