Demo for logging in to Facebook API
Screen shots for Android application:
Screen shots for iOS application:
Screen shots for UWP application:
Watch a video demo: https://youtu.be/xGW9Q4atJNc
Demo for login to Facebook API from Xamarin Forms
Demo for logging in to Facebook API
Screen shots for Android application:
Screen shots for iOS application:
Screen shots for UWP application:
Watch a video demo: https://youtu.be/xGW9Q4atJNc
webview not showing but am told to log in
Title - You login with facebook only where you generated client id. But i want to login with different facebook account. How is possible?Can you please tell us how to do that.Is it possible.
Actual result - Once you generated client id from one account then can't use for another account.
Expected result - Allow to any kind of other facebook account.
I was wandering if i take your facebook login page only from xamarin.android but i cant uderstand how to do it, can you help me?
Hi Houssem, thanks for this great library. Just a wee question: how do I get user email id?
Cheers mate.
Hi ,
I have downloaded the project from git , and when i try to run on android . After clicking on first facebook login button . it navigated me to the page where it displays an error message.
I implemented everything in your video but when i press the butto says the following:
"Not Logged In. you are not logged in. please login and try again"
Below is my code :
using System;
using System.Collections.Generic;
using diabetics_app.ViewModels;
using Xamarin.Forms;
namespace diabetics_app.Main
{
public partial class FacebookProfilePage : ContentPage
{
/// <summary>
/// Make sure to get a new ClientId from:
/// https://developers.facebook.com/apps/
/// </summary>
private string ClientId = "134161603894277";
// 134161603894277
public FacebookProfilePage()
{
InitializeComponent();
var apiRequest =
"https://www.facebook.com/v2.10/dialog/oauth?client_id="
+ ClientId
+ "&display=popup&response_type=token&redirect_uri=http://www.facebook.com/connect/login_success.html";
var webView = new WebView
{
Source = apiRequest,
HeightRequest = 1
};
webView.Navigated += WebViewOnNavigated;
Content = webView;
}
private async void WebViewOnNavigated(object sender, WebNavigatedEventArgs e)
{
var accessToken = ExtractAccessTokenFromUrl(e.Url);
if (accessToken != "")
{
var vm = BindingContext as FacebookViewModel;
await vm.SetFacebookUserProfileAsync(accessToken);
Content = MainStackLayout;
}
}
private string ExtractAccessTokenFromUrl(string url)
{
if (url.Contains("access_token") && url.Contains("&expires_in="))
{
var at = url.Replace("https://www.facebook.com/connect/login_success.html#access_token=", "");
if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
{
at = url.Replace("http://www.facebook.com/connect/login_success.html#access_token=", "");
}
var accessToken = at.Remove(at.IndexOf("&expires_in="));
return accessToken;
}
return string.Empty;
}
}
}
I am able to login with the client id given... but when i try to run the example with my own client ID it crashes with a request error..
Can you share your dashboard configuration at facebook developer???
I already have the redirect url configured with http://www.facebook.com/connect/login_success.html
Hi,
thanks for your work.
but what will happen if i want to sign in with another user?? or i want to logout?
how can this be done?
thansks
var userJson = await httpClient.GetStringAsync(requestUrl);
`this code is throwing an error
the error i get is
StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:\r\n{\r\nWWW-Authenticate: OAuth "Facebook Platform" "invalid_request" "(#12) bio field is deprecated for versions v2.8 and higher
I am sending following as a post request.
` public async void WebViewOnNavigated(object sender, WebNavigatedEventArgs e)
{
var accessToken = ExtractAccessTokenFromUrl(e.Url);
Console.WriteLine("Token ==>"+accessToken);
if (accessToken != "")
{
try
{
await GetFacebookProfileAsync(accessToken);
Console.WriteLine("Facebook ID ==>" + facebookProfile.id);
if (string.IsNullOrEmpty(facebookProfile.email))
{
Application.Current.MainPage = new NavigationPage(new Register());
}
else
{
await FacebookLoginSubmit();
}
}
catch (Exception)
{
}
}
}
async Task<FacebookProfileResponse> GetFacebookProfileAsync(string accessToken)
{
var requestUrl =
"https://graph.facebook.com/v2.7/me/"
+ "?fields=first_name,last_name,email"
+ "&access_token=" + accessToken;
var httpClient = new HttpClient();
var userJson = await httpClient.GetStringAsync(requestUrl);
facebookProfile = JsonConvert.DeserializeObject<FacebookProfileResponse>(userJson);
return facebookProfile;
}
private string ExtractAccessTokenFromUrl(string url)
{
if (url.Contains("access_token") && url.Contains("&expires_in="))
{
var at = url.Replace("https://www.facebook.com/connect/login_success.html#access_token=", "");
if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
{
at = url.Replace("http://www.facebook.com/connect/login_success.html#access_token=", "");
}
var accessToken = at.Remove(at.IndexOf("&expires_in="));
return accessToken;
}
return string.Empty;
}`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.