【发布时间】:2014-03-09 20:48:42
【问题描述】:
我想使用 Twitter4J 访问公共流 API 示例。 我在 Twitter 上创建了一个应用程序并生成了相关的密钥和令牌(使用 Twitter 门户)。
但它总是无法通过身份验证。
这是根据文档的代码。许多现有的论坛帖子已过时。
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true);
cb.setOAuthConsumerKey("XXXXX");
cb.setOAuthConsumerSecret("XXXXXXXX");
cb.setOAuthAccessToken("xxxxxxxx-xxxxxxxxxxxxxxxxxxxxxx");
cb.setOAuthAccessTokenSecret("XXXXXXXXXXXXXXXXXXXXXXX");
OAuthAuthorization auth = new OAuthAuthorization(cb.build());
TwitterStreamFactory factory = new TwitterStreamFactory();
this.twitterStream = factory.getInstance(auth);
this.twitterStream.addListener(listener);
this.twitterStream.sample();
我得到的错误是:
401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Error 401 Unauthorized</title>
</head>
<body>
<h2>HTTP ERROR: 401</h2>
<p>Problem accessing '/1.1/statuses/sample.json?stall_warnings=true'. Reason:
<pre> Unauthorized</pre>
</body>
</html>
【问题讨论】:
-
我不记得了,因为那是很久以前的事了!最后,我不得不手动建立连接并在没有库的情况下自己打开流。
标签: java twitter oauth twitter4j