Xamarin.Android 的 Google 登入

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

转载于:https://www.cnblogs.com/Liddle/p/5409890.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值