Google認証にRestSharpを使用する方法
-
14-11-2019 - |
質問
私は「GoogleでサインインしてWindows Phone 7アプリを構築しました。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?
.
Googleからの応答を得るために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;
});