Come utilizzare RestSharp per Google Authentication?
-
14-11-2019 - |
Domanda
Ho costruito un'app per Windows Phone 7 con una funzione "Accedi con Google".La biblioteca di Google non è compatibile con Windows Phone Runtime, quindi scelgo RestSharp.
L'app ha ricevuto con successo un codice di autenticazione da Google e il passaggio successivo è quello di scambiare il codice per un token di accesso e un aggiornamento del token.Qui ho riscontrato un problema.
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?
.
Non sono sicuro di come usare il metodo client.ExecuteAsync<T>
(o qualsiasi altro sarebbe utile) per ottenere la risposta da Google.C'è qualche altro codice pre-richiesto per me usare tale metodo?Qualcuno può aiutarmi?
Soluzione
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.
Altri suggerimenti
try:
client.ExecuteAsync(request, (response) =>
{
var dataToBeParsed = response.Content;
});