【问题标题】:"No authentication challenges found" with twitter4jtwitter4j 的“未发现身份验证挑战”
【发布时间】:2017-03-16 17:20:53
【问题描述】:

我正在尝试使用 twitter4j 在 Twitter 上签名。
我的代码是

public class MainActivity extends AppCompatActivity {
    private static Twitter twitter;
    private static RequestToken requestToken;
    static String consumerKey = "my_consumer_key";
    static String consumerSecretKey = "my_consumer_secret_key";
    static String accessToken = "my_access_token";
    static String accessSecretToken = "my_access__secret_token";
    User user;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

   final ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true)
            .setOAuthConsumerKey(consumerKey)
            .setOAuthConsumerSecret(consumerSecretKey)
            .setOAuthAccessToken(accessToken)
            .setOAuthAccessTokenSecret(accessSecretToken);
    Thread thread = new Thread(new Runnable()
    {
        @Override
        public void run() {
            try {
                TwitterFactory factory = new TwitterFactory(cb.build());
                Twitter twitter = factory.getInstance();

                System.out.println(twitter.getScreenName());
                     //getting error because of this line

            } catch (TwitterException te) {
                te.printStackTrace();
            }
        }
    });

    thread.start();
}
}

错误:当我运行此代码时,它给我“未找到身份验证挑战”错误。
我已尝试使用之前提出的问题来解决此问题,但失败了。

link to same image(if you don't find it clear here)
谁能告诉我我在这里犯了什么错误?

注意:如果我将 .setApplicationOnlyAuthEnabled(true) 添加到 cb,则会收到一个新错误既没有提供用户 ID/密码,也没有提供 OAuth 消费者密钥/秘密组合。

【问题讨论】:

    标签: java twitter twitter4j


    【解决方案1】:

    试试下面的方法:

       final ConfigurationBuilder cb = new ConfigurationBuilder();
            .setOAuthConsumerKey(consumerKey)
            .setOAuthConsumerSecret(consumerSecretKey)
            .setOAuthAccessToken(accessToken)
            .setOAuthAccessTokenSecret(accessSecretToken);
            OAuthAuthorization auth = new OAuthAuthorization(cb.build());
            Twitter twitter = new TwitterFactory().getInstance(auth);
    

    【讨论】:

      猜你喜欢
      • 2012-10-14
      • 2013-07-05
      • 2013-11-27
      • 1970-01-01
      • 2013-09-05
      • 2015-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多