如何使用RESTSHARP用于Google身份验证?
-
14-11-2019 - |
题
我已经建立了一个Windows Phone 7应用程序,其中包含“使用Google”功能。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?
.
我不确定如何使用client.ExecuteAsync<T>
方法(或任何其他都有用)来获得谷歌的响应。是否有任何其他代码预先要求我使用此类方法?任何人都可以帮助我吗?
解决方案
You need to bind a UI element to display the response. That seems to be the gist of the problem you've outlined.
If you want to display the response in your application, you should have a UI element bound to an internal data structure.
Displaying the response
// in xaml, for example MainPage.xaml
<TextBox x:Name="myResponseTextBox">
// in the corresponding MainPage.xaml.cs
client.ExecuteAsync(request, (response) =>
{
myResponseTextBox.text = response.Content;
});
The Text box will display the result of the callback when it completes.
其他提示
try:
client.ExecuteAsync(request, (response) =>
{
var dataToBeParsed = response.Content;
});
不隶属于 StackOverflow