'why i cant display in web view facebook page login?
im trying implement a button to login with facebook in my app from xamarin forms , first im doing now im doing my code in c# Another error that is not debugging you is that it is not bringing me the token, perhaps that is why it is not allowing me to show the login page

private string ClientId = "12345678910";
private void LogearseFb_Clicked(object sender, EventArgs e)
{
var ApiRequest = "https://www.facebook.com/dialog/oauth?client_id="
+ ClientId + "&display=popup&response_type=token&redirect_uri=https://www.facebook.com/connect/login_success.html";
VistaFacebook.Source = ApiRequest;
VistaFacebook.HeightRequest = 2;
VistaFacebook.Navigated += VistaFacebook_Navigated;
}
private async void VistaFacebook_Navigated(object sender, WebNavigatedEventArgs e)
{
var accessToken = extraerurlToken(e.Url);
if (accessToken != "")
{
await GetFacebookProfileAsync(accessToken);
}
}
public async Task GetFacebookProfileAsync(string accesToken)
{
var requestUrl = "https://graph.facebook.com/v2.6/me/" + "?fields=name,picture,cover,age_range,devices,email,is_verified"
+ "&access_token=" + accesToken;
var httpClient = new HttpClient();
var userJson = await httpClient.GetAsync(requestUrl);
}
private string extraerurlToken(string url)
{
string scheme = "Facebook";
if(url.Contains("access_token") && url.Contains("&expires_in="))
{
var at = url.Replace("https://www.facebook.com/connect/login_success.html#access_token={accessToken}", "");
if (scheme.Equals("Apple")
&& DeviceInfo.Platform == DevicePlatform.iOS
&& DeviceInfo.Version.Major >= 13)
{
// Use Native Apple Sign In API's
at = url.Replace("https://www.facebook.com/connect/login_success.html#access_token={accessToken}","");
}
var accessToken = at.Remove(at.IndexOf("&expires_in="));
return accessToken;
}
return string.Empty;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
