Cannot get request token - Twitter 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(
02-20 14:29:27.995: W/System.err(14145): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(
02-20 14:29:28.005: W/System.err(14145): at$
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(
02-20 14:29:28.005: W/System.err(14145): at oauth.signpost.AbstractOAuthProvider.retrieveToken(
02-20 14:29:28.005: W/System.err(14145): … 2 more

The libs I use:

I suspect there is something wrong with this code:
mHttpOauthprovider = new DefaultOAuthProvider(“”, “”, “”);


Update your code to use the correct OAuth paths:** has been deprecated for some time.


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 = "" + token.Token;

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


Try using “”…

The protocol should be HTTPS. The host should be


thanks taylor - after further investigating I was still calling 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.



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(”,”,”);


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?


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


hi i had same problems (i used same tutorial from,

actualy i already change into :

mHttpOauthprovider = new DefaultOAuthProvider

but in ,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:
05-08 11:47:08.070: W/System.err(20424): at oauth.signpost.AbstractOAuthProvider.retrieveToken(
05-08 11:47:08.070: W/System.err(20424): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(
05-08 11:47:08.070: W/System.err(20424): at$
05-08 11:47:08.070: W/System.err(20424): Caused by:
05-08 11:47:08.075: W/System.err(20424): at
05-08 11:47:08.075: W/System.err(20424): at
05-08 11:47:08.075: W/System.err(20424): at oauth.signpost.basic.HttpURLConnectionResponseAdapter.getContent(
05-08 11:47:08.075: W/System.err(20424): at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(
05-08 11:47:08.080: W/System.err(20424): at oauth.signpost.AbstractOAuthProvider.retrieveToken(
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


You want to keep the callback field on 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.


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) {

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

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

  2. in, 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]);
	} catch (MalformedURLException e) {

	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


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


i am also getting error 401


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