我目前工作在我的Android应用程序集成的Twitter。我把它整合成功在一定程度上。不过,我在下面的情况下获得未找到认证的挑战
例外。
I am currently working on integrating Twitter in my android application. I integrated it successfully to an extent. However I get the No authentication challenges found
exception in following scenario.
程序 - 唯一的身份验证
(不登录电子进入微博)来获取公众的Twitter的饲料。我获取它们成功。
当我尝试回复或转推或将其标记为收藏,我是否已经登录的用户是或不是,如果没有登录的话,我试着先登录,然后做了答复或转推。
,但我得到试图只登陆,所以我没有达到答复或转推上面提到的异常。
I use App-only authentication
(without loging into twitter)to fetch the public feeds from twitter. I fetch them successfully.
When I try to reply or retweet or mark it as favorite, I check if user is already logged in or not, if it is not logged-in then I try to login first and then do the reply or retweet.
But I get above mentioned exception while trying to login only, so I don't reach the reply or retweet.
注意::如果我不使用程序 - 唯一的身份验证
键,选择直接登录(不取公共提要),那么它的工作原理不错,我可以登录。
Note: If I don't use App-only authentication
and choose to login directly(without fetching public feed), then it works fine and I can login.
以下是堆栈跟踪:
11-14 19:33:03.597: W/System.err(3305): No authentication challenges found
11-14 19:33:03.667: W/System.err(3305): Relevant discussions can be found on the Internet at:
11-14 19:33:03.667: W/System.err(3305): http://www.google.co.jp/search?q=9ddbeb3a or
11-14 19:33:03.727: W/System.err(3305): http://www.google.co.jp/search?q=937eec8d
11-14 19:33:03.747: W/System.err(3305): TwitterException{exceptionCode=[9ddbeb3a-937eec8d c8a7b39b-dc5ea0d9], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=3.0.4}
11-14 19:33:03.797: W/System.err(3305): at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:177)
11-14 19:33:03.857: W/System.err(3305): at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
11-14 19:33:03.897: W/System.err(3305): at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:98)
11-14 19:33:03.957: W/System.err(3305): at twitter4j.auth.OAuthAuthorization.getOAuthAccessToken(OAuthAuthorization.java:145)
11-14 19:33:04.097: W/System.err(3305): at twitter4j.auth.OAuthAuthorization.getOAuthAccessToken(OAuthAuthorization.java:165)
11-14 19:33:04.107: W/System.err(3305): at twitter4j.TwitterBaseImpl.getOAuthAccessToken(TwitterBaseImpl.java:381)
编辑:
以下是code我使用基于用户是否登录或不转的配置。
Following is the code I am using to switch the configuration based on whether user is logged in or not.
private TwitterInstance(boolean withLoginConfig) {
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder
.setOAuthConsumerKey(STAConstants.TWITTER_CONSUMER_KEY);
configurationBuilder
.setOAuthConsumerSecret(STAConstants.TWITTER_CONSUMER_SECRET);
// configuration required to fetch feeds without login.
if (!withLoginConfig) {
configurationBuilder.setUseSSL(true);
// IMPORTANT: set T4J to use App-only authentication
configurationBuilder.setApplicationOnlyAuthEnabled(true);
configurationBuilder.setOAuth2TokenType(getOAuth2Token()
.getTokenType());
configurationBuilder.setOAuth2AccessToken(getOAuth2Token()
.getAccessToken());
}
Configuration configuration = configurationBuilder.build();
twitterFactory = new TwitterFactory(configuration);
twitter = twitterFactory.getInstance();
requestToken = null;
}
我搜索的SO和其他网站的解决方案,但是没有得到任何。
I searched for the solution on SO and other sites as well, but did not get any.
任何帮助是非常AP preciated。
Any help is highly appreciated.
推荐答案
我从事一些东西,终于找到了自己的回答我的问题。因此,张贴在这里。
I worked on few things and finally found answer myself to my question. Hence posting here.
问题:未找到认证的挑战
原因:我不发送 AccessToken
在登录后的配置和 AccessTokenSecret
。因此,它没有得到认证数据
Reason : I was not sending AccessToken
and AccessTokenSecret
in configuration after Login. Hence it was not getting the authentication data.
解决方法:
第1步:我用程序 - 唯一的身份验证
(不登录电子进入微博)来获取公众的Twitter的饲料。我取他们的成功。为此,我用 BearerToken
的配置如下:
Step 1: I use App-only authentication
(without loging into twitter) to fetch the public feeds from twitter. I fetch them successfully. For this I use BearerToken
in configuration as follows:
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.setOAuthConsumerKey(Constants.TWITTER_CONSUMER_KEY);
configurationBuilder.setOAuthConsumerSecret(Constants.TWITTER_CONSUMER_SECRET);
configurationBuilder.setUseSSL(true);
// IMPORTANT: set T4J to use App-only authentication
configurationBuilder.setApplicationOnlyAuthEnabled(true);
configurationBuilder.setOAuth2TokenType(getOAuth2Token().getTokenType());
configurationBuilder.setOAuth2AccessToken(getOAuth2Token().getAccessToken());
第二步::当我尝试回复或转推或将其标记为收藏,我是否已经登录的用户是或不是,如果没有登录的话,我试着先登录然后再做答复或转推。为此,我使用下面的配置。
Step 2: When I try to reply or retweet or mark it as favorite, I check if user is already logged in or not, if it is not logged-in then I try to login first and then do the reply or retweet. For this I use following configuration.
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.setOAuthConsumerKey(Constants.TWITTER_CONSUMER_KEY);
configurationBuilder.setOAuthConsumerSecret(Constants.TWITTER_CONSUMER_SECRET);
这会给我 RequestToken
这反过来又会给我 AccessToken
和 AccessTokenSecret
。
This will give me RequestToken
which in turn will give me the AccessToken
and AccessTokenSecret
.
第三步:然后我用下面的配置为后续的请求没有任何问题
Step 3 : Thereafter I use following configuration for subsequent requests without any problem.
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.setOAuthConsumerKey(Constants.TWITTER_CONSUMER_KEY);
configurationBuilder.setOAuthConsumerSecret(Constants.TWITTER_CONSUMER_SECRET);
configurationBuilder.setOAuthAccessToken(getAccessToken()); // from sharedPreferences
configurationBuilder.setOAuthAccessTokenSecret(getAccessTokenSecret()); // from sharedPreferences
相关推荐
最新文章