Twitter oAuth callbackUrl - localhost development

后端 未结 17 1329
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-27 10:21

Is anyone else having a difficult time getting Twitters oAuth\'s callback URL to hit their localhost development environment. Apparently it has been disabled recently. http:

相关标签:
17条回答
  • 2020-11-27 11:06

    I just had to do this last week. Apparently localhost doesn't work but 127.0.0.1 does Go figure.

    This of course assumes that you are registering two apps with Twitter, one for your live www.mysite.com and another for 127.0.0.1.

    0 讨论(0)
  • 2020-11-27 11:07

    Yes, it was disabled because of the recent security issue that was found in OAuth. The only solution for now is to create two OAuth applications - one for production and one for development. In the development application you set your localhost callback URL instead of the live one.

    0 讨论(0)
  • 2020-11-27 11:09

    Just put http://127.0.0.1:xxxx/ as the callback url, where xxxx is the port for your framework

    0 讨论(0)
  • 2020-11-27 11:10

    These are the steps that worked for me to get Facebook working with a local application on my laptop:

    • goto apps.twitter.com
    • enter the name, app description and your site URL Note: for localhost:8000, use 127.0.0.1:8000 since the former will not work
    • enter the callback URL matching your callback URL defined in TWITTER_REDIRECT_URI your application Note: eg: http://127.0.0.1/login/twitter/callback (localhost will not work).
    • Important enter both the "privacy policy" and "terms of use" URLs if you wish to request the user's email address
    • check the agree to terms checkbox
    • click [Create Your Twitter Application]
    • switch to the [Keys and Access Tokens] tab at the top
    • copy the "Consumer Key (API Key)" and "Consumer Secret (API Secret)" to TWITTER_KEY and TWITTER_SECRET in your application
    • click the "Permissions" tab and set appropriately to "read only", "read and write" or "read, write and direct message" (use the least intrusive option needed for your application, for just and OAuth login "read only" is sufficient
    • Under "Additional Permissions" check the "request email addresses from users" checkbox if you wish for the user's email address to be returned to the OAuth login data (in most cases check yes)
    0 讨论(0)
  • 2020-11-27 11:15

    This is how i did it:

    Registered Callback URL: http://127.0.0.1/Callback.aspx

       OAuthTokenResponse authorizationTokens = 
            OAuthUtility.GetRequestToken(ConfigSettings.getConsumerKey(), 
                                         ConfigSettings.getConsumerSecret(), 
                                         "http://127.0.0.1:1066/Twitter/Callback.aspx");
    

    ConfigSettings:

    public static class ConfigSettings
    {
        public static String getConsumerKey()
        {
            return System.Configuration.ConfigurationManager.AppSettings["ConsumerKey"].ToString();
        }
    
        public static String getConsumerSecret()
        {
            return System.Configuration.ConfigurationManager.AppSettings["ConsumerSecret"].ToString();
        }
    
    }
    

    Web.config:

    <appSettings>
    
        <add key="ConsumerKey" value="xxxxxxxxxxxxxxxxxxxx"/>
        <add key="ConsumerSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/>
    
    </appSettings>
    

    Make sure you set the property 'use dynamic ports' of you project to 'false' and enter a static port number instead. (I used 1066).

    I hope this helps!

    0 讨论(0)
  • 2020-11-27 11:17

    I was working with Twitter callback url on my localhost. If you are not sure how to create a virtual host ( this is important ) use Ampps. He is really cool and easy. In a few steps you have your own virtual host and then every url will work on it. For example:

    1. download and install ampps

    2. Add new domain. ( here you can set for example twitter.local) that means your virtual host will be http://twitter.local and it will work after step 3.

    3. I am working on Win so go under to your host file -> C:\Windows\System32\Drivers\etc\hosts and add line: 127.0.0.1 twitter.local

    Restart your Ampps and you can use your callback. You can specify any url, even if you are using some framework MVC or you have htaccess url rewrite.

    Hope This Help! Cheers.

    0 讨论(0)
提交回复
热议问题