Liddle

Google  的 Sing-In 功能,Xamarin 放在 Google Play Services - Plus 內。
所以我們要先引入這個 Component 

然後一樣是在 https://developers.google.com/mobile/add 平台上,選擇 Android 後,加入 Sign-In 功能。

加入憑證的 SHA-1 指紋。這樣就完成設定的部分。


然後程式碼部分,請大家注意這個 GoogleApiClientBuilder 類別
Google 已經將許多呼叫 Google 服務的方法以這個類別作為統一入口。

mGoogleApiClient = new GoogleApiClient.Builder (this)
                .AddConnectionCallbacks (this)
                .AddOnConnectionFailedListener (this)
                .AddApi (PlusClass.API)
                .AddScope (new Scope (Scopes.Profile))
                .Build ();

以這個類別建構起的實體運行 Connect() 後,即可串接Google Service

mGoogleApiClient.Connect ();

而後以下列方法獲得資料

var person = PlusClass.PeopleApi.GetCurrentPerson (mGoogleApiClient);


再運用這段程式碼時,請注意在UI這邊要放 Google 自製的 SignInButton 物件
再由程式這邊實作 

GoogleApiClient.IConnectionCallbacks, GoogleApiClient.IOnConnectionFailedListener

 

<com.google.android.gms.common.SignInButton
            android:id="@+id/sign_in_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:visibility="visible"
            tools:visibility="gone" />

 

程式碼:https://github.com/FangHuaiAn/Xamarin-AndroidTips

參考:https://developers.google.com/identity/sign-in/android/sign-in?configured=true

分类:

技术点:

相关文章:

  • 2021-12-06
  • 2022-12-23
  • 2021-08-06
  • 2022-01-22
  • 2021-05-21
  • 2021-12-16
  • 2021-04-11
猜你喜欢
  • 2021-12-11
  • 2021-12-16
  • 2022-01-19
  • 2021-05-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案