title | author | description | keywords | dev_langs | ||
---|---|---|---|---|---|---|
Facebook Service |
nmetulev |
The Facebook Service allows you to retrieve or publish data to the Facebook graph. Examples of the types of objects you can work with are Posts, Tagged Objects, and the primary user feed (outdated docs). |
windows 10, uwp, windows community toolkit, uwp community toolkit, uwp toolkit, Facebook Service |
|
Warning
The Facebook Service is no longer available in the Windows Community Toolkit. The underlying dependent library was no longer maintained.
The Facebook Service allows you to retrieve or publish data to the Facebook graph. Examples of the types of objects you can work with are Posts, Tagged Objects, and the primary user feed.
[!div class="nextstepaction"] Try it in the sample app
The Windows Store SID is a unique value per application generated, and it not tied to the actual store publication. Creating a local application will give you a valid SID that you can use for debugging against Facebook.
// Put the following code in your mainform loaded event
// Note that this will not work in the App.xaml.cs Loaded
#if DEBUG
System.Diagnostics.Debug.WriteLine("Windows Store SID = " + Microsoft.Toolkit.Uwp.Services.Facebook.FacebookService.Instance.WindowsStoreId);
#endif
' Put the following code in your mainform loaded event
' Note that this will not work in the App.xaml.cs Loaded
#If DEBUG Then
System.Diagnostics.Debug.WriteLine("Windows Store SID = " & Microsoft.Toolkit.Uwp.Services.Facebook.FacebookService.Instance.WindowsStoreId)
#End If
Note
You may have to turn on the Output window in Visual Studio to see this debug writeline.
The above code will output something like this:
Windows Store SID = ms-app://s-1-15-2-12341451-1486691014-2395677208-123421631-1234998043-1234490472-123452499/
When entering the value into the Facebook Developer site you must strip the ms-app:// and the trailing / off the string.
- To get a Facebook.WindowsStoreID, go to: https://developers.facebook.com/apps.
- Select Create a New App ID, to start integration Facebook into your app or website.
- Click, Create a New App
- From the app Dashboard choose the Settings item on the left. It should select the Basic item under it by default.
- +Add Platform choose Windows App. Leave the Namespace and App Domains entries blank.
- Enter the Windows Store SID from within your app (see Getting Windows Store SID section)
- From left side menu choose +Add Product Click to add Facebook Login. Ensure you set the following options in the UI:
Setting | Value |
---|---|
Client OAuth Login | Yes |
Web OAuth Login | No |
Embedded Browser OAuth Login | Yes |
Force Web OAuth Redirection | No |
Login from Devices | No |
Valid OAuth redirect URIs | Blank |
// Initialize service
FacebookService.Instance.Initialize(AppIDText.Text);
// Login to Facebook
if (!await FacebookService.Instance.LoginAsync())
{
return;
}
// Get user's feed
ListView.ItemsSource = await FacebookService.Instance.RequestAsync(FacebookDataConfig.MyFeed, 50);
// Get current user profile picture
ProfileImage.DataContext = await FacebookService.Instance.GetUserPictureInfoAsync();
// Post a message on your wall using Facebook Dialog
await FacebookService.Instance.PostToFeedWithDialogAsync(TitleText.Text, DescriptionText.Text, UrlText.Text);
// Get current user's photo albums
await FacebookService.Instance.GetUserAlbumsAsync();
// Get current user's photos by album Id
await FacebookService.Instance.GetUserPhotosByAlbumIdAsync(addedItem.Id);
' Initialize service
FacebookService.Instance.Initialize(AppIDText.Text)
' Login to Facebook
If Not Await FacebookService.Instance.LoginAsync() Then
Return
End If
' Get user's feed
ListView.ItemsSource = Await FacebookService.Instance.RequestAsync(FacebookDataConfig.MyFeed, 50)
' Get current user profile picture
ProfileImage.DataContext = Await FacebookService.Instance.GetUserPictureInfoAsync()
' Post a message on your wall using Facebook Dialog
Await FacebookService.Instance.PostToFeedWithDialogAsync(TitleText.Text, DescriptionText.Text, UrlText.Text)
' Get current user's photo albums
Await FacebookService.Instance.GetUserAlbumsAsync()
' Get current user's photos by album Id
Await FacebookService.Instance.GetUserPhotosByAlbumIdAsync(addedItem.Id)
FacebookAlbum has properties to hold album details
Property | Type | Description |
---|---|---|
Cover_Photo | FacebookPhoto | Gets or sets cover_photo property |
Description | string | Gets or sets description property |
Id | string | Gets or sets id property |
Name | string | Gets or sets name property |
Picture | FacebookPictureData | Gets or sets picture property |
Configuration object for specifying richer query information
Field | Type | Description |
---|---|---|
MyFeed | FacebookDataConfig | Gets a predefined config to get user feed. The feed of posts (including status updates) and links published by this person, or by others on this person's profile |
MyPosts | FacebookDataConfig | Gets a predefined config to show only the posts that were published by this person |
MyTagged | FacebookDataConfig | Gets a predefined config to show only the posts that this person was tagged in |
Property | Type | Description |
---|---|---|
Query | string | Gets or sets the query string for filtering service results |
Facebook OAuth tokens
Property | Type | Description |
---|---|---|
AppId | string | Gets or sets facebook AppId |
WindowsStoreId | string | Gets or sets Windows Store ID |
FacebookAlbum has properties to hold photo details
Property | Type | Description |
---|---|---|
Album | int | Gets or sets album property |
Created_Time | int | Gets or sets time the entity instance was created |
Id | string | Gets or sets id property |
Images | int | Gets or sets images property |
Link | string | Gets or sets a link to the entity instance |
Name | string | Gets or sets name property |
Picture | string | Gets or sets picture property |
Class for presenting picture data returned from service provider
Property | Type | Description |
---|---|---|
Id | string | Gets or sets the ID of the picture |
Is_Silhouette | bool | Gets or sets a value indicating whether the picture is a silhouette or not |
Link | string | Gets or sets the url of the page with the picture |
Url | string | Gets or sets an url to the picture |
Holds picture data
Property | Type | Description |
---|---|---|
Data | FacebookPicture | Gets or sets data property |
Holds image details
Property | Type | Description |
---|---|---|
Height | string | Gets or sets height property |
Source | string | Gets or sets source property |
Width | string | Gets or sets width property |
Holds facebook post data
Property | Type | Description |
---|---|---|
Id | string | Gets or sets id property |
Message | string | Gets or sets message or post text |
Created_Time | DateTime | Gets or sets time the entity instance was created |
Link | string | Gets or sets a link to the entity instance |
Full_Picture | string | Gets or sets a link to the accompanying image |
Type to handle paged requests to Facebook Graph
Constructor | Description |
---|---|
FacebookRequestSource(FacebookDataConfig, string, string, int) | Initializes a new instance of the FacebookRequestSource<T> class |
Methods | Return Type | Description |
---|---|---|
GetPagedItemsAsync(int, int, CancellationToken) | Task<IEnumerable<T>> | Returns strong typed page of data |
Class for connecting to Facebook
Property | Type | Description |
---|---|---|
WindowsStoreId | string | Gets a Windows Store ID associated with the current app |
Instance | FacebookService | Gets public singleton property |
LoggedUser | string | Gets the current logged user name |
Provider | FBSession | Gets a reference to an instance of the underlying data provider |
B | int | Description |
B | int | Description |
Methods | Return Type | Description |
---|---|---|
Initialize(FacebookOAuthTokens, FacebookPermissions) | bool | Initialize underlying provider with relevant token information |
LoginAsync() | Task<bool> | Login with set of required requiredPermissions |
LogoutAsync() | Task | Log out of the underlying service instance |
RequestAsync(FacebookDataConfig, int) | Task<List<FacebookPost>> | Request list data from service provider based upon a given config / query |
RequestAsync<T>(FacebookDataConfig, int, string) | Task<List<T>> | Request list data from service provider based upon a given config / query |
RequestAsync(FacebookDataConfig, int, int) | Task<IncrementalLoadingCollection<FacebookRequestSource<FacebookPost>, FacebookPost>> | Request list data from service provider based upon a given config / query |
RequestAsync<T>(FacebookDataConfig, int, int, string) | Task<IncrementalLoadingCollection<FacebookRequestSource<T>, T>> | Request generic list data from service provider based upon a given config / query |
GetUserPictureInfoAsync() | Task<FacebookPicture> | Returns the FacebookPicture object associated with the logged user |
GetUserAlbumsAsync(int, string) | Task<List<FacebookAlbum>> | Retrieves list of user photo albums |
GetUserAlbumsAsync(int, int, string) | Task<IncrementalLoadingCollection<FacebookRequestSource<FacebookAlbum>, FacebookAlbum>> | Retrieves list of user photo albums |
GetUserPhotosByAlbumIdAsync(string, int, string) | Task<List<FacebookPhoto>> | Retrieves list of user photos by album id |
GetUserPhotosByAlbumIdAsync(string, int, int, string) | Task<IncrementalLoadingCollection<FacebookRequestSource<FacebookPhoto>, FacebookPhoto>> | Retrieves list of user photos by album id |
GetPhotoByPhotoIdAsync(string) | Task<FacebookPhoto> | Retrieves a photo by id |
PostToFeedWithDialogAsync(string) | Task<bool> | Enables posting data to the timeline using Facebook dialog |
Facebook Service Sample Page Source. You can see this in action in the Windows Community Toolkit Sample App.
Device family | Universal, 10.0.16299.0 or higher |
---|---|
Namespace | Microsoft.Toolkit.Uwp.Services |
NuGet package | Microsoft.Toolkit.Uwp.Services |