本文介绍了Windows Phone上的TweetSharp中无法使用GetRequestToken的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能再在TwitterService中使用GetRequestToken

I can't use GetRequestToken in TwitterService anymore

还有GetAccessToken!

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));
                }

            });

它给了我

'TweetSharp.TwitterService'不包含'GetRequestToken'的定义,并且找不到扩展方法'GetRequestToken'接受类型为'TweetSharp.TwitterService'的第一个参数(您是否缺少using指令或程序集引用? )

'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?)

推荐答案

我通过通过Hammock( https://github.com/danielcrenna/hammock )

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

这是代码

 /// <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));
    }

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.

这篇关于Windows Phone上的TweetSharp中无法使用GetRequestToken的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-20 01:47