Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use RestSharp for Google Authentication?

I have built a windows phone 7 app with a "sign in with google" function. Google library is not compatible with windows phone runtime so I choose RestSharp.

The app has successfully received a authentication code from Google, and the next step is to exchange the code for an access token and a refresh token. Here I encountered some problem.

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?

I'm not sure how to use the client.ExecuteAsync<T> method (or any other would be helpful) to get the response from Google. Is there any other code pre-requested for me to use such method? Can anybody help me?

like image 322
yifei Avatar asked Oct 09 '22 12:10

yifei


2 Answers

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.

like image 86
Chewbarkla Avatar answered Oct 15 '22 23:10

Chewbarkla


try:

client.ExecuteAsync(request, (response) =>
{
    var dataToBeParsed = response.Content;
});
like image 26
maka Avatar answered Oct 16 '22 00:10

maka