GetRequestToken is not working in TweetSharp on Windows Phone

孤者浪人 提交于 2019-12-04 18:38:29

I solved it by getting Request Token via Hammock(https://github.com/danielcrenna/hammock)

and here is the code

 /// <summary>
    /// Gets Twitter Request Token 
    /// </summary>
    private void GetTwitterToken()
    {
        var credentials = new OAuthCredentials
        {
            Type = OAuthType.RequestToken,
            SignatureMethod = OAuthSignatureMethod.HmacSha1,
            ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
            ConsumerKey = "Your Consumer Key",
            ConsumerSecret = "Your Consumer Secret",
            Version = TwitterSettings.OAuthVersion,
            CallbackUrl = TwitterSettings.CallbackUri
        };

        var client = new RestClient
        {
            Authority = "https://api.twitter.com/oauth",
            Credentials = credentials,
            HasElevatedPermissions = true,
        };

        var request = new RestRequest
        {
            Path = "/request_token"
        };
        client.BeginRequest(request, new RestCallback(TwitterRequestTokenCompleted));
    }

and

private void TwitterRequestTokenCompleted(RestRequest request, RestResponse response, object userstate)
    {
        _oAuthToken = GetQueryParameter(response.Content, "oauth_token");
        _oAuthTokenSecret = GetQueryParameter(response.Content, "oauth_token_secret");
        var authorizeUrl = TwitterSettings.AuthorizeUri + "?oauth_token=" + _oAuthToken;

        if (String.IsNullOrEmpty(_oAuthToken) || String.IsNullOrEmpty(_oAuthTokenSecret))
        {
            Dispatcher.BeginInvoke(() => MessageBox.Show("error calling twitter"));
            return;
        }

        Dispatcher.BeginInvoke(() => AuthBrowser.Navigate(new Uri(authorizeUrl)));
    }

and You can do the same with access token.

Have you checked to see if the TweetSharp Library supports Windows Phone 8?

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