Your users can login to your application using Facebook after which you can request information about them. Additional setup is required on Facebook and in the generated solution - see the setup section at the bottom of the page for more information
Once a user has successfully logged in their access token is automatically saved so you do not need to direct the user to the login screen everytime - check "WSANativeFacebook.IsLoggedIn" first.
A users access token generally expires after 60 days and at this point they will have to be directed back to the login page again. You can tell when an access token has expired as any calls to facebook apis will fail and the error message will have the AccessTokenExpired property set, you can also check the "WSANativeFacebook.AccessTokenExpiry" property. Calling login for a user who was previously logged in will result in a silent re-authentication if possible
C#using CI.WSANative.Facebook;
Initialises the Facebook api - you should call this when your app starts up
You can find the facebookid on your Facebook developer account under the app you created
Redirect uri should be the exact OAuth redirect uri that you entered on the facebook developer portal
C#WSANativeFacebook.Initialise("facebookId", "redirectUri");
Shows the Facebook login dialog to the user and if the login is successful returns data about them
All public permissions are requested by default - you can request others but they require approval by Facebook
If the login is successful WSANativeFacebook.IsLoggedIn will be set to true
C#WSANativeFacebook.Login(null, r =>
{
if (r.Success)
{
WSAFacebookUser user = r.User;
}
});
Logs the user out i.e removes their access token and sets "IsLoggedIn" to false
If you pass true for uninstall then your app will be uninstalled from the users Facebook account
C#WSANativeFacebook.Logout(uninstall);
Requests details about the logged in user based on the permissions you asked for when they logged in. User details are automatically fetched when you call "Login", but you can call this again to refresh them
C#WSANativeFacebook.GetUserDetails(r =>
{
if(r.Success)
{
WSAFacebookUser user = r.Data;
}
});
Allows you to manually call any read operation on the graph api - see the api reference here
The response will contain a string property called Data which has the json response from the server
C#WSANativeFacebook.GraphApiRead("me", null, r =>
{
if (r.Success)
{
string response = r.Data;
}
});
Allows a user to publish a story to their timeline - this does not require any special permissions nor does it require the user to be currently logged in
For this dialog to work properly you must add your domain to the App domains field in the Facebook developer portal
You don't need to specify all of the parameters, null the ones you don't want
The closed action is raised when the dialog is closed
C#WSANativeFacebook.ShowFeedDialog("link", "hastag", () =>
{
});
Allows the user to send invites / requests to their Facebook friends - this does not require any special permissions nor does it require the user to be currently logged in
For this dialog to work properly you must add your domain to the App domains field in the Facebook developer portal
The closed action is raised when the dialog is closed and includes the ids of the Facebook users who requests were sent to
C#WSANativeFacebook.ShowRequestDialog("title", "message", (userIds) =>
{
});
Allows the user to send a private message containing a link to their Facebook friends - this does not require any special permissions nor does it require the user to be currently logged
For this dialog to work properly you must add your domain to the App domains field in the Facebook developer portal
The closed action is raised when the dialog is closed
C#WSANativeFacebook.ShowSendDialog("link", () =>
{
});
Perform the following steps on the Facebook developer website
- Register as a developer here
- Create a new app
- From the app dashboard click the plus icon next to products from the left menu
- Add facebook login
- Under Client OAuth Settings enable the following (Client OAuth Login, Enable Login for Web, Enable Login for Embedded Browser)
- Add a to url to Valid OAuth Redirect URIs. It should be a domain that belongs to you but the exact route doesn't need to exist as it is just used for redirecting. e.g "https://claytoninds.com/login-success" where "/login-success" may or may not be a real page
- Under setting / basic - note the App ID, you’ll need this in your code
- Under settings / advanced - enable Native or desktop app
Perform the following steps in the generated uwp solution
- Open the solution and add the Nuget package Microsoft.UI.Xaml
- Download this file and add it to the project which has the same name as your game. Make sure it is physcially in the same folder as MainPage.xaml
- Open MainPage.xaml.cpp and add the following includes near the top
C##define GENERATED_PROJECT 1
#include "WSAFacebookBridge.h"
#include "FacebookManager.h"
- At the bottom of the MainPage.xaml.cpp constructor add the following line
C#FacebookManager::Initialise(m_DXSwapChainPanel);
- Open the apps manifest file and add the internet client capability