Cannot get request token - Twitter 1.1


#1

I get this error today when using Twitter4J 3.0.3 using OAuth.

02-20 14:29:27.995: W/System.err(14145): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: Service provider responded in error: 301 (Moved Permanently)
02-20 14:29:27.995: W/System.err(14145): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:218)
02-20 14:29:27.995: W/System.err(14145): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:74)
02-20 14:29:28.005: W/System.err(14145): at app.jp.cropnet.twitter.TwitterApp$2.run(TwitterApp.java:255)
02-20 14:29:28.005: W/System.err(14145): Caused by: oauth.signpost.exception.OAuthCommunicationException: Service provider responded in error: 301 (Moved Permanently)
02-20 14:29:28.005: W/System.err(14145): at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:245)
02-20 14:29:28.005: W/System.err(14145): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:193)
02-20 14:29:28.005: W/System.err(14145): … 2 more

The libs I use:
signpost-commonshttp4-1.2.1.2.jar
signpost-core-1.2.1.2.jar
twitter4j-core-3.0.3.jar
twitter4j-media-support-3.0.3.jar

I suspect there is something wrong with this code:
mHttpOauthprovider = new DefaultOAuthProvider(“http://twitter.com/oauth/request_token”, “http://twitter.com/oauth/access_token”, “http://twitter.com/oauth/authorize”);


#2

Update your code to use the correct OAuth paths: https://api.twitter.com/oauth/*http://twitter.com/oauth/* has been deprecated for some time.


#3

I am also experiencing this problem, however i am using
public Uri GetAuthorisationUrl(OAuthToken token)
{
if (token == null)
throw new ArgumentNullException(“token”, “The OAuthToken that was passed was null.”);

		string url = "http://api.twitter.com/oauth/authorize?oauth_token=" + token.Token;

		return new Uri(url);
	}
so taylor's suggestion will not work for me

#4

Try using “https://api.twitter.com/oauth/authorize?oauth_token=”…

The protocol should be HTTPS. The host should be api.twitter.com


#5

thanks taylor - after further investigating I was still calling twitter.com/oauth as well it was a constant that was getting set in a seperatley compiled source. I have updated and wanted to let it be known that the first purposed solution was ultimately the answer to my problems.

Thanks,
Jeff


#6

Its required to make twitter connection using https rather than http due to security reason according the new change in Twitter APIs.

Use as:

new DefaultOAuthProvider(
https://api.twitter.com/oauth/request_token”,
https://api.twitter.com/oauth/access_token”,
https://api.twitter.com/oauth/authorize”);


#7

I get a Error 401 when i try to connect to oauth/access_token
But the oauth/authorize and request_token work ok.

Am I using this in the right order?
I am having user click sign in button
I send my app consumer keys to oauth/request_token and reveive oauth token OK
I then send the token to oauth/authenticate?oauth_token=$oauth_token
User signs in and return to my callback URL OK
I receive oauth_token + oauth_verifier OK
I send the token and verifier to oauth/request_token and receive oauth_token + oauth_token_secret OK

My problem is i am unable to use the oauth_token + oauth_token_secret to get the user credentials as in 1.1/account/verify_credentials.json

Any ideas anyone please?


#8

I think where you’ve gone astray is that you’re sending the oauth_token and verifier to oauth/request_token, when what you’re wanting to do is exchange the request token you already have (with aid from the oauth_verifieer) for an access token, so your request should be to oauth/access_token


#9

hi i had same problems (i used same tutorial from http://www.londatiga.net/it/how-to-post-twitter-status-from-android/comment-page-2/),

actualy i already change into :

mHttpOauthprovider = new DefaultOAuthProvider
(“https://api.twitter.com/oauth/request_token”,
https://api.twitter.com/oauth/access_token”,
https://api.twitter.com/oauth/authorize”);

but in https://dev.twitter.com/apps/ ,Callback URL i left in BLANK(None) , i got error :

05-08 11:47:08.070: W/System.err(20424): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: https://api.twitter.com/oauth/request_token
05-08 11:47:08.070: W/System.err(20424): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
05-08 11:47:08.070: W/System.err(20424): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
05-08 11:47:08.070: W/System.err(20424): at sg.tv.SocialGate.TwitterCore.TwitterApp$2.run(TwitterApp.java:152)
05-08 11:47:08.070: W/System.err(20424): Caused by: java.io.FileNotFoundException: https://api.twitter.com/oauth/request_token
05-08 11:47:08.075: W/System.err(20424): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
05-08 11:47:08.075: W/System.err(20424): at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)
05-08 11:47:08.075: W/System.err(20424): at oauth.signpost.basic.HttpURLConnectionResponseAdapter.getContent(HttpURLConnectionResponseAdapter.java:18)
05-08 11:47:08.075: W/System.err(20424): at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:228)
05-08 11:47:08.080: W/System.err(20424): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:189)
05-08 11:47:08.080: W/System.err(20424): … 2 more

but when I fill that Callback URL , i didnt see any error… i want Callback URL fill blank, so what have to do??

thank you, sorry for bad english


#10

You want to keep the callback field on dev.twitter.com populated. Then use your intended callback explicitly on the oauth/request_token. The explicit callback won’t function without a value existing on your app record.


#11

i already have callback_url in my java :
public static final String CALLBACK_URL = “twitterapp://connect”;
String authUrl = “”;
try {
authUrl = mHttpOauthprovider.retrieveRequestToken(mHttpOauthConsumer, CALLBACK_URL);
} catch (Exception e) {
e.printStackTrace();
}

if i filled edittext callback url in dev.twitter.com i didnt get any error, but if i didnt fill it, always go to catch exception. that’s why i confuse until right now


#12
  1. Use your twitter app name instead of “twitterapp” e.g
    public static final String CALLBACK_URL = “ABC://connect”;

  2. in TwitterApp.java, use your app name where it says replace … e.g

private String getVerifier(String callbackUrl) {
String verifier = “”;

	try {
		callbackUrl = callbackUrl.replace("ABC", "http");

		URL url = new URL(callbackUrl);
		String query = url.getQuery();

		String array[] = query.split("&");

		for (String parameter : array) {
			String v[] = parameter.split("=");

			if (URLDecoder.decode(v[0]).equals(
					oauth.signpost.OAuth.OAUTH_VERIFIER)) {
				verifier = URLDecoder.decode(v[1]);
				break;
			}
		}
	} catch (MalformedURLException e) {
		e.printStackTrace();
	}

	return verifier;
}
  1. Put this code in your Manifest file , (replace activity name with your own)







Also avoid duplicate status update , it will throw error if you will try to post same status again and again


#13

Great @episod with this protocol the code run good! Thanks.


#14

i am also getting error 401


#15

i cant redirect to twitter accept page???i dun no why?