在Windows 8应用程序中进行REST请求

本文关键字:REST 请求 Windows 应用程序 | 更新日期: 2023-09-27 17:49:50

我正在尝试从Twitter获取一些数据。

我通常使用Hammock包,但它在Windows 8应用程序中不可用。

var credentials = new OAuthCredentials
            {
                Type = OAuthType.ProtectedResource,
                SignatureMethod = OAuthSignatureMethod.HmacSha1,
                ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
                ConsumerKey = AppSettings.consumerKey,
                ConsumerSecret = AppSettings.consumerKeySecret,
                Token = this.accessToken,
                TokenSecret = this.accessTokenSecret,
                Version = "1.0"
            };

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

                var restRequest = new RestRequest
                {
                    Credentials = credentials,
                    Path = "1.1/statuses/update_with_media.json",
                    Method = WebMethod.Post

                };

                restRequest.AddField("status", "Test");





                restClient.BeginRequest(restRequest,RequestCallBack);



        private void AutreRequestCallBack(RestRequest request, RestResponse response, object obj)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                if (reponse.StatusCode == HttpStatusCode.OK)
                {

                   MessaBox.Show("Success");

                }


                else
                {
                    MessageBox.Show("Failure");

                }
            }
                );

        }

如何在Windows 8应用程序中使用类似的方法获取(或发布)Twitter数据?

在Windows 8应用程序中进行REST请求

我建议你看一下LinqToTwitter。Nuget上有,你很快就能上手。它适用于Windows 8、Windows 8.1和Windows Phone。