Search code examples
phptwittertwitter-oauth

Twitter Log in with Localhost


So I am trying to make my users connect their twitter accounts to my website's accounts by making them log in to twitter. How I want it to work is that, they will click a button it will pop-up (or redirect to) a twitter page where they can login. Then I will get their twitter username (yes only the username).

How can I achieve this? I would really appreciate an example, so far the tutorials and guides in official twitter website have not really helped me that much.

I am using only php and javascript and the website is running on localhost. I have created a developer account on twitter but I am not sure what my "Website Url"(It does not accept http://localhost or http://127.0.0.1) and "Callback Url" should be.

Thank you in advance, and sorry if this something very basic or simple.


Solution

  • Please note - any callback URL that you use with the POST oauth/request_token endpoint will have to be whitelisted within the Twitter app settings in the app details page of developer portal

    From: https://developer.twitter.com/en/docs/basics/authentication/oauth-1-0a/obtaining-user-access-tokens

    Twitter will not whitelist localhost - so you will need a temporary domain while testing.