不支持在嵌入式浏览器中登录



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

我们没有LoginBehavior选项。有人知道如何在xamarin。forms中处理这个吗?

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

要捕获来自在线服务的重定向,你需要实现一个带有IntentFilter的活动,该活动定义了一个datasscheme。

最后我得到了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帐户登录,您首先必须从设备的浏览器手动注销。

最新更新