I've been able to authenticate multiple Twitter accounts for months now, however I just changed my app's permissions to allow DM viewing. After that I reauthentiacted my accounts and the first one worked fine, but any additional account did not.
I decided to print out the consumer key, consumer secret, access token and access token secret to the console. For the my first account there are no spaces and they look correct. However the second account's access token is 10 characters longer than any of the access tokens before I allowed direct messages. Also whenever I attempt to authenticate I get this error:
400:The request was invalid. An accompanying error message will explain why. This is the status code will be returned during version 1.0 rate limiting(https://dev.twitter.com/pages/rate-limiting). In API v1.1, a request without authentication is considered invalid and you will get this response.
message - Bad Authentication data.
code - 215
According to the error message and some google searches it seems like this error is ran whenever a request is made without authenticating. However I am authenticating. Also whenever I change the keys in any way it gives me a completely different error about invalid or expired tokens (error 89).
This only happens with additional accounts, and not the first account I authenticate (the first account works perfectly, as expected). This is the code I'm running:
public class Tweeter {
private String consumerKey = null;
private String consumerSecret = null;
private String accessToken = null;
private String accessSecret = null;
private Twitter twitter = null;
public Tweeter(String consumerKey, String consumerSecret, String accessToken, String accessSecret) {
this.consumerKey = consumerKey;
this.consumerSecret = consumerSecret;
this.accessToken = accessToken;
this.accessSecret = accessSecret;
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret).setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessSecret);
TwitterFactory factory = new TwitterFactory(cb.build());
twitter = factory.getInstance();
Logger.log("\"" + factory.getInstance().getConfiguration().getOAuthConsumerKey() + "\"");
Logger.log("\"" + factory.getInstance().getConfiguration().getOAuthConsumerSecret() + "\"");
Logger.log("\"" + factory.getInstance().getConfiguration().getOAuthAccessToken() + "\"");
Logger.log("\"" + factory.getInstance().getConfiguration().getOAuthAccessTokenSecret() + "\"");
}
public String getConsumerKey() {
return consumerKey;
}
public String getConsumerSecret() {
return consumerSecret;
}
public String getAccessToken() {
return accessToken;
}
public String getAccessSecret() {
return accessSecret;
}
public Twitter getTwitter() {
return twitter;
}
}
This is the same code I've used in the project I'm working on for months now, even with some of the same additional Twitter accounts. The only thing that changed is the app permissions now allow me to view DMs. Any ideas how I can get this working again? Thanks
The problem is solved. Not sure why this was happening but I tried to reauthenticate additional accounts and it works now. Not sure if there was a problem on Twitter's end or what, I do not believe that I've changed any of the code that was affecting this system in any way.