Facebook 正在終止通過嵌入式瀏覽器登錄。我已經在 Xamarin.Forms 中使用 CustomRenderer 實作了 FB 登錄。
因為我們沒有 LoginBehavior 選項。那么有誰知道如何在 Xamarin.Forms 中處理這個問題?
uj5u.com熱心網友回復:
最好的解決方案是在 CustomTab 中打開登錄頁面,Android 提供了這樣的選項卡,因此不必呼叫外部瀏覽器(我不知道 Xamarin 是否提供自己的類來使用 OAuth)。
public void OpenWebsiteInApp(string url)
{
// Use the Android custom tabs to display the webpage inside the app.
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.Build();
customTabsIntent.LaunchUrl(_applicationContext, Uri.Parse(url));
}
要捕獲來自在線服務的重定向,您需要使用定義 DataScheme 的 IntentFilter 來實作一個活動。
uj5u.com熱心網友回復:
最后我得到了 Xamarin.Forms 的解決方案。我已按照本教程進行操作,問題已解決。
https://evgenyzborovsky.com/2018/03/09/using-native-facebook-login-button-in-xamarin-forms/
成功登錄后,我們將獲取 Access_token 和 userid 值,通過使用它我們可以輕松獲取用戶詳細資訊,例如名字、姓氏。
這是相同的代碼:
var client = new System.Net.Http.HttpClient();
var url = $"https://graph.facebook.com/{facebookResponse.userId}?
fields=id,first_name,last_name,email,picture&access_token=
{facebookResponse.accessToken}";
var response = await client.GetAsync(url);
var result = response.Content.ReadAsStringAsync().Result;
var resultobject = JsonConvert.DeserializeObject<FacebookResponse>(result);
限制:
- 您不能更改登錄按鈕圖示或文本屬性,如字體和大小等。
- 如果您想使用其他 FB 帳戶登錄,您首先必須手動從設備的瀏覽器中注銷。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/313158.html
標籤:C# 沙马林 xamarin.forms 安卓系统 Facebook登入
