如何使用RestSharp进行Google身份验证?

yif*_*fei 5 .net c# windows-phone-7 restsharp

我已经构建了一个带有"登录谷歌"功能的Windows Phone 7应用程序.Google库与Windows Phone运行时不兼容,因此我选择了RestSharp.

该应用已成功从Google收到验证码,下一步是交换代码以获取访问令牌和刷新令牌.在这里我遇到了一些问题.

var request = new RestRequest(this.TokenEndPoint, Method.POST);
request.AddParameter("code", code);
request.AddParameter("client_id", this.ClientId);
request.AddParameter("client_secret", this.Secret);
request.AddParameter("redirect_uri", "http://localhost");
request.AddParameter("grant_type", "authorization_code");
client.ExecuteAsync<???>(request, (response) =>
            {
                var passIn = response;
            }); // how to use this method?
Run Code Online (Sandbox Code Playgroud)

我不确定如何使用该client.ExecuteAsync<T>方法(或其他任何有用的方法)来获取Google的回复.是否还有其他代码要求我使用此类方法?有谁能够帮我?

小智 3

您需要绑定一个 UI 元素来显示响应。这似乎就是您所概述的问题的要点。

如果要在应用程序中显示响应,则应该将 UI 元素绑定到内部数据结构。

显示响应

// 在xaml中,例如MainPage.xaml

<TextBox x:Name="myResponseTextBox">
Run Code Online (Sandbox Code Playgroud)

// 在对应的MainPage.xaml.cs中

client.ExecuteAsync(request, (response) =>
{

   myResponseTextBox.text = response.Content; 

}); 
Run Code Online (Sandbox Code Playgroud)

回调完成后,文本框将显示回调结果。