代码之家  ›  专栏  ›  技术社区  ›  Divyesh

登录嵌入式浏览器弃用

  •  0
  • Divyesh  · 技术社区  · 4 年前

    Facebook正在终止通过嵌入式浏览器登录。我已经在Xamarin.Forms中使用CustomRenderer实现了FB登录。

    在这方面,我们没有登录行为的选项。有人知道如何用Xamarin.Forms处理这个问题吗?

    0 回复  |  直到 4 年前
        1
  •  0
  •   martinstoeckli    4 年前

    最好的解决方案是在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));
        }
    

    要捕获来自在线服务的重定向,您需要使用定义DataSchema的IntentFilter来实现一个活动。

        2
  •  0
  •   Divyesh    4 年前

    最后,我得到了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);            
    

    局限性

    1. 您不能更改登录按钮图标或文本属性,如字体和大小等。
    2. 若您想使用另一个FB帐户登录,您首先必须手动从设备的浏览器中注销。
    推荐文章