私はXamarin Androidを学びましたが、私はGoogle SignInを実装したいと思います...しかし、私はそれをすることができません。私はちょうどクライアントIDを使用する必要がありますか?私はインターネットでいくつかの例をキャッチしますが、何も動作しません...誰かが例を与えることができますか?私はXamarinでこれをどうやってやり遂げることができますか?Xamarin Android Google Plus SignIn
ありがとうございました!
マイコード:
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Gms.Common.Apis;
using Android.Gms.Common;
using System;
using Android.Gms.Plus;
using Android.Content;
using Android.Runtime;
using Android.Gms.Plus.Model.People;
namespace LoginGoogle
{
[Activity(Label = "LoginGoogle", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity, GoogleApiClient.IConnectionCallbacks,
GoogleApiClient.IOnConnectionFailedListener
{
private GoogleApiClient googleApiClient;
private SignInButton btnGooglePlus;
private ConnectionResult connectionResult;
private bool intentProgress;
private bool signInClick;
private bool infoPopulated;
private TextView lblName;
private TextView lblTagLine;
private TextView lblBraggingRights;
private TextView lblGender;
private TextView lblRelationship;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
btnGooglePlus = FindViewById<SignInButton>(Resource.Id.btnGooglePlus);
btnGooglePlus.Click += btnGooglePlus_Click;
lblName = FindViewById<TextView>(Resource.Id.lblName);
lblTagLine = FindViewById<TextView>(Resource.Id.lblTagLine);
lblBraggingRights = FindViewById<TextView>(Resource.Id.lblBraggingRights);
lblGender = FindViewById<TextView>(Resource.Id.lblGender);
lblRelationship = FindViewById<TextView>(Resource.Id.lblRelationship);
GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this);
builder.AddConnectionCallbacks(this);
builder.AddOnConnectionFailedListener(this);
builder.AddApi(PlusClass.API);
builder.AddScope(PlusClass.ScopePlusProfile);
builder.AddScope(PlusClass.ScopePlusLogin);
//Build our GoogleApiClient
googleApiClient = builder.Build();
}
void btnGooglePlus_Click(object sender, EventArgs e)
{
if (!googleApiClient.IsConnecting)
{
signInClick = true;
resolveSigInError();
}
}
private void resolveSigInError()
{
if (!googleApiClient.IsConnected)
{
//No need to resolve errors
return;
}
if (connectionResult.HasResolution)
{
try
{
intentProgress = true;
StartIntentSenderForResult(connectionResult.Resolution.IntentSender, 0, null,
0, 0, 0);
} catch (Android.Content.IntentSender.SendIntentException e)
{
intentProgress = false;
googleApiClient.Connect();
}
}
}
protected override void OnActivityResult(int requestCode,
[GeneratedEnum] Result resultCode, Intent data)
{
if(requestCode == 0)
{
if(resultCode != Result.Ok)
{
signInClick = false;
}
intentProgress = false;
if (googleApiClient.IsConnecting)
{
googleApiClient.Connect();
}
}
}
protected override void OnStart()
{
base.OnStart();
googleApiClient.Connect();
}
protected override void OnStop()
{
base.OnStop();
if (googleApiClient.IsConnected)
{
googleApiClient.Disconnect();
}
}
public void OnConnected(Bundle connectionHint)
{
//Successful login
signInClick = false;
if (PlusClass.PeopleApi.GetCurrentPerson(googleApiClient) != null)
{
IPerson plusUser = PlusClass.PeopleApi.GetCurrentPerson(googleApiClient);
if (plusUser.HasDisplayName)
{
lblName.Text += plusUser.DisplayName;
}
if (plusUser.HasTagline)
{
lblTagLine.Text += plusUser.Tagline;
}
if (plusUser.HasBraggingRights)
{
lblBraggingRights.Text += plusUser.BraggingRights;
}
{
switch (plusUser.RelationshipStatus)
{
case 0:
lblRelationship.Text += "Single";
break;
case 1:
lblRelationship.Text += "In a relationship";
break;
case 2:
lblRelationship.Text += "Engaged";
break;
case 3:
lblRelationship.Text += "Married";
break;
case 4:
lblRelationship.Text += "It's complicated";
break;
case 5:
lblRelationship.Text += "In an open relationship";
break;
case 6:
lblRelationship.Text += "Widowed";
break;
case 7:
lblRelationship.Text += "In a domestic partnership";
break;
case 8:
lblRelationship.Text += "In a civil union";
break;
default:
lblRelationship.Text += "Unknown";
break;
}
}
if (plusUser.HasGender)
{
switch (plusUser.Gender)
{
case 0:
lblGender.Text += "Male";
break;
case 1:
lblGender.Text += "Female";
break;
case 2:
lblGender.Text += "Other";
break;
default:
lblGender.Text += "Unknown";
break;
}
infoPopulated = true;
}
}
}
public void OnConnectionSuspended(int cause)
{
throw new NotImplementedException();
}
public void OnConnectionFailed(ConnectionResult result)
{
if (intentProgress)
{
//Store the ConnectionResult so that we can use it later when the user
//clicks 'sign in'
connectionResult = result;
if (signInClick)
{
//The user has already clicked 'signin' so we attempt to resolve all
//errors until the user is signed in
resolveSigInError();
}
}
}
}
}
enter code here
:私はあなたがして、クライアントIDでログインしようとすることができると思います/ watch?v = 3wH-g59JfFY)と[Xamarin Androidチュートリアル37 Google+ログイン第2部](https://www.youtube.com/watch?v=GKoXQTFCWuE)をご覧ください。お役に立てれば。 –