共用方式為


Facebook(存檔)

警告

本文件已被歸檔,且該元件目前版本的 Windows 社群工具包中無法取得。

社群歡迎表達興趣或參與,但我們要特別說明:

  • 我們不願意將這個元件移植到 8.x。
  • 目前尚無已知推薦的替代品來取代這個成分。

如需詳細資訊,請參閱:

以下是原始文件。


警告

Facebook 服務已不再出現在 Windows 社群工具包中。 底層的依賴函式庫不再被維護。

Facebook 服務允許您取得或發布資料到 Facebook 圖表。 你可以處理的物品類型範例包括貼文、標記物件及主要用戶動態消息。

取得 Windows Store SID

Windows Store SID 是每個應用程式產生的唯一值,且不綁定於實際的商店發佈。 建立本地應用程式會給你一個有效的 SID,可以用來針對 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

備註

你可能需要在 Visual Studio 開啟輸出視窗,才能看到這個除錯寫入行。

上述程式碼會輸出類似這樣的內容:

Windows Store SID = ms-app://s-1-15-2-12341451-1486691014-2395677208-123421631-1234998043-1234490472-123452499/

在輸入值到 Facebook 開發者網站時,必須將「ms-app://」和結尾的「/」從字串中移除。

在 Facebook 開發者網站上建立新應用程式

  1. 要取得 Facebook.WindowsStoreID,請前往: https://developers.facebook.com/apps
  2. 選擇 建立新 App ID,開始將 Facebook 整合進你的應用程式或網站。
  3. 點擊, 建立新應用程式
  4. 在應用程式的儀表板中,選擇左側 的設定 項目。 它預設應該會選擇「基本」項目。
  5. +新增平台 ,選擇 Windows 應用程式。 名稱 空間應用程式網域 的條目保持空白。
  6. 在你的應用程式內輸入 Windows Store SID (參見 取得 Windows Store SID 章節)
  7. 從左側選單選擇 +新增產品 ,點擊新增 Facebook 登入。 請確保你在介面中設定以下選項:
Setting 價值觀
用戶端 OAuth 登入 Yes
網頁 OAuth 登入
嵌入式瀏覽器 OAuth 登入 Yes
強制網路 OAuth 重定向
從裝置登入
有效的 OAuth 重定向 URI 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)

Facebook相簿課程

Facebook相簿有存放相簿細節的屬性

屬性

房產 類型 Description
封面照片 Facebook照片 取得或設定 cover_photo 屬性
Description 字串 取得或設定描述屬性
身份識別碼 字串 取得或設定 id 屬性
名稱 字串 取得或設定名稱屬性
圖片 FacebookPictureData 取得或設定圖片屬性

FacebookDataConfig 類別

用於指定更豐富查詢資訊的設定物件

Fields

領域 類型 Description
MyFeed FacebookDataConfig 會取得預先定義的配置來抓取使用者動態消息。 此人或其他人在此個人檔案上發布的貼文(包括狀態更新)和連結的動態消息流。
我的貼文 FacebookDataConfig 取得一個預先定義的配置,只顯示這個人發表的貼文。
我的標籤 FacebookDataConfig 取得預先定義的配置,只顯示該人被標記的貼文。

屬性

房產 類型 Description
Query 字串 取得或設定查詢字串以過濾服務結果

FacebookOAuthTokens 類別

Facebook OAuth 代幣

屬性

房產 類型 Description
AppId 字串 取得或設定 Facebook AppID
Windows Store ID 字串 取得或設定 Windows 商店 ID

Facebook攝影課程

Facebook相簿有可存放照片細節的屬性

屬性

房產 類型 Description
影集 整數 (int) 取得或設定相簿屬性
建立時間 整數 (int) 取得或設定實體實例建立的時間
身份識別碼 字串 取得或設定 id 屬性
圖片 整數 (int) 取得或設定影像屬性
Link 字串 取得或設定指向實體例項的連結
名稱 字串 取得或設定名稱屬性
圖片 字串 取得或設定圖片屬性

Facebook圖片課程

用于表示服務提供者回傳的圖片資料的類別

屬性

房產 類型 Description
身份識別碼 字串 取得或設定圖片的識別碼
Is_Silhouette 布爾 (bool) 會取得或設定一個數值,指示該圖片是否為剪影
Link 字串 取得或設定帶有圖片的頁面網址
網址 字串 取得或設定圖片的網址

FacebookPictureData 類別

儲存圖片資料

屬性

房產 類型 Description
資料 Facebook圖片 取得或設定資料屬性

FacebookPlatformImageSource 類別

儲存影像細節

屬性

房產 類型 Description
高度 字串 取得或設定高度屬性
來源 字串 取得或設定來源屬性
寬度 字串 取得或設定寬度屬性

FacebookPost 類別

儲存 Facebook 貼文資料

屬性

房產 類型 Description
身份識別碼 字串 取得或設定 id 屬性
Message 字串 取得或設定訊息或貼文內容
建立時間 DateTime 取得或設定實體實例建立的時間
Link 字串 取得或設定指向實體例項的連結
全貌 字串 取得或設定連結至附帶圖片

FacebookRequestSource<T> 類別

輸入以處理 Facebook Graph 的分頁請求

建構函式

建構函式 Description
FacebookRequestSource(FacebookDataConfig, string, string, int) 初始化一個新FacebookRequestSource<T>類別的實例

Methods

Methods 返回類型 Description
GetPagedItemsAsync(int, int, CancellationToken) 任務<IEnumerable<T>> 回傳強類型資料頁面

Facebook服務課程

連接 Facebook 的課程

屬性

房產 類型 Description
Windows Store ID 字串 會取得與目前應用程式綁定的 Windows 商店 ID
實例 Facebook服務 獲得公共單項財產
已登入使用者 字串 取得目前已登入的使用者名稱
Provider FBSession 取得底層資料提供者實例的參考
B 整數 (int) Description
B 整數 (int) Description

Methods

Methods 返回類型 Description
Initialize(FacebookOAuthTokens, FacebookPermissions) 布爾 (bool) 初始化基礎提供者,並使用相關的代幣資訊
LoginAsync() 任務<布爾> 必須具備 requiredPermissions 的一套權限才能登入。
登出非同步() 任務 登出底層服務實例
RequestAsync(FacebookDataConfig, int) 任務<清單<FacebookPost>> 根據特定設定/查詢,從服務提供者取得請求清單資料
RequestAsync<T>(FacebookDataConfig, int, string) 任務<清單<T>> 根據特定設定/查詢,從服務提供者取得請求清單資料
RequestAsync(FacebookDataConfig, int, int) 任務<漸進載入集合<Facebook請求來源<Facebook貼文>,Facebook貼文>> 根據特定設定/查詢,從服務提供者取得請求清單資料
RequestAsync<T>(FacebookDataConfig, int, int, string) 任務<IncrementalLoadingCollection<FacebookRequestSource<T>, T>> 根據指定的設定/查詢,向服務提供者請求通用清單資料
GetUserPictureInfoAsync() 任務<FacebookPicture> 與已登入使用者關聯的 FacebookPicture 物件會被回傳
GetUserAlbumsAsync(int, string) 任務<清單<Facebook相簿>> 取得使用者相簿清單
GetUserAlbumsAsync(int, int, string) 任務<增量載入集合<FacebookRequest來源<Facebook相簿>,Facebook相簿>> 取得使用者相簿清單
GetUserPhotosByAlbumIdAsync(字串, 整數, 字串) 任務<清單<Facebook照片>> 依相簿 ID 檢索使用者照片清單
GetUserPhotosByAlbumIdAsync(string, int, int, string) 任務<增量載入集合<Facebook請求來源<Facebook照片>,Facebook照片>> 依相簿 ID 檢索使用者照片清單
GetPhotoByPhotoIdAsync(string) 任務<Facebook照片> 透過 id 取得照片
PostToFeedWithDialogAsync(string) 任務<布爾> 可透過 Facebook 對話框將資料發佈到時間軸

範例專案

Facebook 服務範例頁面來源。 你可以在 Windows 社群工具包範例應用程式中看到這個功能的運作

需求

裝置系列 通用版,10.0.16299.0 或更高等級
Namespace Microsoft.Toolkit.Uwp.Services
NuGet 套件 Microsoft.Toolkit.Uwp.Services

API