The remote server returned an error: (401) Unauthorized. Twitter oAuth

删除回忆录丶 提交于 2019-12-09 10:21:45

问题


I am trying to make work twitter oAuth with twitterizer, but I am unable.

I am getting the following error:

The remote server returned an error: (401) Unauthorized.

When my callback url is a localhost.

If my callback url is oob, for the pin flow it works correctly.

Here is my code:

 public ActionResult LogOn(string returnUrl, bool? perm)
    {
        string consumerKeyTw = @"UF3F72XqfGShQs7juKMApA";
        string consumerSecretTW = "secret";
        OAuthTokenResponse requestToken = OAuthUtility.GetRequestToken(consumerKeyTw, consumerSecretTW, "http://localhost:58892/Twitterr/OAuth");

        // Direct or instruct the user to the following address:
        Uri authorizationUri = OAuthUtility.BuildAuthorizationUri(requestToken.Token);

        return new RedirectResult(authorizationUri.ToString(), false);
    }

I never get the token when I setup the callback url. On twitter I register my callback url localhost.

Am I missing somthing?

Any idea whats going on?


回答1:


Make sure your application is set as a web application on the development portal. For the callback address there, make sure you use an incorrect address (like your application's homepage), then specify the real address at runtime.

Web applications can use pin-based authentication, but desktop applications cannot use the web flow.




回答2:


I had this same problem and fixed it by adding a "Callback URL" in the Twitter App Settings page. I didn't have my domain name yet so I simply added a unused domain name like: http://www.website.com. The Twitterizer request call immediatly started working for me.

Fissh



来源:https://stackoverflow.com/questions/6267096/the-remote-server-returned-an-error-401-unauthorized-twitter-oauth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!