Как использовать RestSharp для аутентификации Google?
-
14-11-2019 - |
Вопрос
Я построил приложение Windows Phone 7 с функцией «Войти с Google».Библиотека Google не совместима с Windows Phone Runtime, поэтому я выбираю 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>
(или любой другой, будет полезен), чтобы получить ответ от Google.Есть ли другой код предварительно запрашивал для меня использовать такой метод?Кто-нибудь может помочь мне?
Решение
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;
});