Why can't I use localhost as my OAuth callback?

@laserlemon Steve Richert

GitHub OAuth conveniently allows you to specify a "localhost" callback URL for use in local development. I'm getting an invalid error for the following callback URL:


and I assume it's because of the localhost (or maybe the port). Could you help me out with that? Thank you!

2 years 9 weeks ago


@episod Taylor Singletary

You can provide any valid URL with a domain name we recognize on the application details page. OAuth 1.0a requires you to send a oauth_callback value on the request token step of the flow and we'll accept a dynamic locahost-based callback on that step.

2 years 9 weeks ago
@marqia_lynn marqia williams

I keep getting invalid url callback when I enter a valid callback url. In addition, it will not allow me to leave it blank.

2 years 4 weeks ago
@BenJohnstonSF ben johnston

i am getting the same problem as @marqia_lynn. Why would twitter not just let you put in localhost?

2 years 3 weeks ago
@episod Taylor Singletary

The OAuth callback field on your app management screen is just a placeholder! Treat it as if it means nothing, and that you just need to put a valid URL there in order to use callback-based auth. Try putting "http://yourusername.com".

In OAuth 1.0a, you are required to send an oauth_callback parameter to the oauth/request_token every time, regardless of what you put in this field. At the oauth/request_token step, you can provide a http://localhost/blah/blah/blah callback if you like. You just can't associate localhost with your application record on dev.twitter.com.

2 years 3 weeks ago
@AmbiAdh msPerfect

use instead of localhost.
This helps in local development.

1 year 44 weeks ago
@Sir03834855 咔咔Sir

you can use http: to replace localhost

1 year 43 weeks ago
@Rick24Sharma Rick Sharma

why should not we use our local host server for the connection

1 year 32 weeks ago
@GDBalaji Balaji GD is this right

1 year 27 weeks ago

@GDBalaji: You should use for this. When you use an IP address in a URL, the IP is put in place of the domain, not before it.

1 year 27 weeks ago
@nihase123 senthilkumar kumaran

I tried using but no use, it is throwing "Not a valid URL format". I'm not sure how to configure this. This is frustrating me :( and please note that this issue is still OPEN. Can anybody help me to fix this. Suggestions would be really helpful to me, as i'm working in Oauth and struggling to configure APIv1.1 in my localhost. thanks in advance!

39 weeks 1 day ago
@cjmcguinness Charles McGuinness

It doesn't matter what you put into the settings for your app. Put in the URL of your website, for example. Just pass along your localhost callback in the actual API call to authorize. I actually write my code in a way that it looks at the current URL to generate a callback URL, so the code works unchanged whether testing on my PC or on the server in the cloud.

As an example, if you are using Java Servlets (which you are probably not, but...), you can use code like this:

  1.         TwitterFactory twitterFactory;
  2.      twitterFactory = new TwitterFactory();
  3.      Twitter twitter = twitterFactory.getInstance();
  4.         twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
  7.      StringBuffer callbackURL = request.getRequestURL();
  8.         int index = callbackURL.lastIndexOf("/");
  9.         callbackURL.replace(index, callbackURL.length(), "").append("/callback");
  11.      try
  12.         {
  13.           RequestToken twitterRequestToken = twitter.getOAuthRequestToken(callbackURL.toString());
  14.            request.getSession().setAttribute("requestToken", twitterRequestToken);
  16.          String authorizationUrl = twitterRequestToken.getAuthorizationURL();
  17.            response.sendRedirect(twitterRequestToken.getAuthenticationURL());
  18.      }
  19.       catch (TwitterException e)
  20.      {
  21.           throw new ServletException(e);
  22.      }
39 weeks 1 day ago
@Peggy6668 PeggyLin

out with that? Thank you

35 weeks 5 days ago
@Smart_Casper Casper Smart

try this

24 weeks 1 day ago
@IkoRubio vinz iko rubio

twitter work for local host

4 weeks 6 hours ago
@chleozam Karen Farzam

same with me, I used the localhost but can not have it work...

19 weeks 3 days ago
@chleozam Karen Farzam

you can open a file from the terminal in order to change the local host name:
$ subl /etc/hosts
you might need to use the super user to get access, in such a case do this in the terminal:
$ sudo vi /etc/hosts
then you can just change the name localhost to my-localhost.com

19 weeks 1 day ago
@Ghodmode Vince Aggrippino

Okay. I've read this whole thread and, to me, it's about as clear as mud. I realize that it's an old thread and that configuration options may have changed.

In the Twitter app configuration there's a field for a callback URL on the Settings tab. I realize that we can't put a localhost domain there.

On the OAuth tool tab, there's a Request Settings block with two fields: Request URI and Request query. The Request URI field is automatically populated with https://api.twitter.com/1/. This seems to make sense since we're making a request to the Twitter API.

The Request query isn't for a full URL. It's just the part after the question mark in a URL which we might not even use for our application.

So, is the correct procedure to put our localhost callback URL into the Request URI field?

17 weeks 5 days ago
@sarathsprakash sarathsreeprakash

You could use as the oauthback. It works for me .
You have to specify the port.

16 weeks 5 days ago
@fbncs Fabiano

it doesn't work on windows 8.1...

the loopback IP is ::1 (ipv6), and returns invalid url format...


12 weeks 3 days ago
@cseer90 Sayed Ahad Abbas

nothing, as suggested by anyone of you above, is working and I'm still stuck with creation of a sample login app. I'm trying to create it for localhost but it says
Not a valid URL format

14 weeks 6 days ago
@GombertM Gombi

Hello everybody.
To my point of view, this is frankly restrictive. I am stucked for 3 days on this issue of localhost redirection. I'm really disappointed. If someone has a real trick to escape from this problem, i'd be recognicient. Thanks per advance

12 weeks 4 days ago
@fbncs Fabiano not working on windows 8.1, i think because ipv6 it's activated, and I'm having errors...

I try to navigate on browser, or ping, and I'm receaving a bad request url... invalid format.

I've discovered that doing a ping to localhost, and the IP is ::1

12 weeks 3 days ago
@ArpillePointCom Arpille.com

I have put http://arpille.com inthe URL callback,
and error red message : Invalid URL
Whet does this field ask for ?
I tried a domain, I tried a full file adress with domain,
Same error.
Thanks for help.

12 weeks 1 day ago
@30thJune1986 OMG, That B.A.S.E!!

I had been using http:

Worked fine until it stopped working... my access token are suddenly not recognized anymore. Wondering if it is because they are passed as argument of the aformentioned callback url.

I'm really clueless as I haven't changed the code at all.

11 weeks 4 days ago
@sumitjasuja90 Sumit jasuja

i have given call back url in request but twitter api returning on url that is mentioned in app setting. i want twitter to return on url given in code. how do i can do ?

2 weeks 6 days ago