GetRequestToken is not working in TweetSharp on Windows Phone

拜拜、爱过 提交于 2020-01-13 06:42:06

问题


I can't use GetRequestToken in TwitterService anymore

and also GetAccessToken!

TwitterService service = new TwitterService("ConsumerKey", "ConsumerKeySecret");    
service.GetRequestToken(Constants.CallbackUri, (request, response) =>
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    Request = request;
                    var uri = service.GetAuthorizationUri(request);
                    Dispatcher.BeginInvoke(() => AuthBrowser.Navigate(uri));
                }

            });

it gives me:

'TweetSharp.TwitterService' does not contain a definition for 'GetRequestToken' and no extension method 'GetRequestToken' accepting a first argument of type 'TweetSharp.TwitterService' could be found (are you missing a using directive or an assembly reference?)


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/18207773/getrequesttoken-is-not-working-in-tweetsharp-on-windows-phone

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