Facebook authentication and get information about the user with Plugin.Facebook
- When we have a Xamarin.Forms Portable application we have to click on References -> Manage NuGet Packages.
- Type in: Plugin.Facebook and Install.
- After the Install it creates 4 folders: Models, View, ViewModel és Services.
- If it is possible, leaves the ViewModel folder intact.
Models folder: It contains the response Object Model(User’s information)
Services:
var requestUrl =
“https://graph.facebook.com/v2.7/me/?fields=name,picture,work,website,religion,location,locale,link,cover,age_range,bio,birthday,devices,email,first_name,last_name,gender,hometown,is_verified,languages&access_token=”
+ accessToken;
It is necessary to define the query URL, which ask for details from Facebook down. After the me/? and for the &access_token we can define, which information do we need about the user.
View: FacebookProfileCsPage.cs is a Page, which display the data.
What must we do before we are using this package?
https://developers.facebook.com/apps/ we have to register our application like web application.
If we are ready, we have to add to our Product a Facebook Login and we have to write theese URLs to the Valid OAuth Redirect URLs.
https://www.facebook.com/connect/login_success.html
and http://www.facebook.com/connect/login_success.html just in case.
private string ClientId = “165942640479284”; We have to override this string of ours application AppID.
Link about this NuGet package: https://channel9.msdn.com/Blogs/MVP-Windows-Dev/Login-with-Facebook-in-Xamarin-Forms