0

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 

답변

1

가에서 구글 기호에 대한 xamarin sample를 참조하십시오이 샘플에서는 클라이언트 ID가 필요하지 않습니다.. 더 많은 Google 로그인 정보는 Google 개발 document을 확인하십시오.

나는 인터넷에서 몇 가지 예를 잡을하지만 아무것도

는 당신이 응용 프로그램을 허가하지 않을 수 있습니다 생각 ... 작동하지 않습니다.

샘플을 다운로드하고 사용하기 전에 Google Developers Console에서 앱을 승인했는지 확인하십시오.

  1. 열고 link을 승인했다.

  2. 프로젝트 이름 (작성한 이름)을 만들고 패키지 이름을 추가하십시오. 이 샘플에서 패키지 이름은 com.xamarin.signinquickstart입니다.

  3. SHA-1을 받으려면 link을 참조하십시오.

  4. 데모 앱을 빌드하고 배포하고 Google 계정으로 로그인하십시오.

스크린 샷 :

enter image description here

하지만 난 그렇게 할 수 있도록하고 있지 않다. 클라이언트 ID 만 사용해야합니까?

어떻게 구글 document에 따르면

에 클라이언트 ID 로그인을 사용하는 방법. 난 당신에 의해 클라이언트 ID로 로그인을 시도 할 수 있다고 생각 : 당신을 도울 수있는 비디오 자습서는

GoogleSignInOptions gso = new  GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) 
      .RequestIdToken("YOUR_CLIENT_ID") 
      .RequestEmail() 
      .Build(); 
mGoogleApiClient = new GoogleApiClient.Builder (this) 
    .EnableAutoManage(mLoginFragment, failedHandler) 
    .AddApi (Auth.GOOGLE_SIGN_IN_API,gso) 
    .Build() 
+0

있습니다 - [자 마린 안드로이드 자습서 (36)의 Google+ 로그인 1 부 (https://www.youtube.com/watch? v = 3wH-g59JfFY) 및 [Xamarin Android Tutorial 37 Google+ 로그인 2 부] (https://www.youtube.com/watch?v=GKoXQTFCWuE) 희망이 도움이됩니다. –