Share via


搭配服務主體設定檔使用 Power BI SDK

本文說明如何搭配 服務主體設定檔 使用 SDK。 有兩種方式可將 Power BI 用戶端連線至服務主體設定檔。 您可以:

一旦用戶端與設定檔相關聯,您就可以 從 Power BI 用戶端 取得目前的服務主體設定檔。

使用服務主體設定檔建立 Power BI 用戶端

var profileObjectId = new Guid("81f24a6d-7ebb-4478-99c7-2c36f7870a26"); 
var powerBIclient = new PowerBIClient(credentials, profileObjectId: profileObjectId);

當您使用設定檔物件識別碼建立 Power BI 用戶端時,使用用戶端的每個 API 呼叫都會在 X-PowerBI-profile-id 要求標頭中有 。

例如:

GET https://powerbiapi.analysis-df.windows.net/v1.0/myorg/groups


Authorization: Bearer eyJ0eXAiO.....5U_g
X-PowerBI-profile-id: 81f24a6d-7ebb-4478-99c7-2c36f7870a26

在 API 要求呼叫上設定設定檔

或者,您可以使用 API 多載 PowerBIClient 方法 WithHttpMessagesAsync 中的 屬性,在 API 要求 customHeaders 中指定設定檔識別碼。

var powerBIclient = new PowerBIClient(credentials); 
var profileHeader = new Dictionary<string, List<string>>(); 
profileHeader.Add("X-PowerBI-profile-id", new List<string> { "81f24a6d-7ebb-4478-99c7-2c36f7870a26" }); 
var groups = await powerBIclient.Groups.GetGroupsWithHttpMessagesAsync(customHeaders: profileHeader); 

例如,

GET https://powerbiapi.analysis-df.windows.net/v1.0/myorg/groups 

Authorization: Bearer eyJ0eXAiO.....5U_g 
X-PowerBI-profile-id: 81f24a6d-7ebb-4478-99c7-2c36f7870a26 

在上述程式碼範例中,設定檔標頭 不是 用戶端預設標頭的一部分,因為程式碼不會新增設定檔標頭。 您必須使用每個 API 要求來指定設定檔標頭。

請確定您避免重複。 例如,使用設定檔物件識別碼建立用戶端,然後使用 API 要求指定標頭會導致未經授權的錯誤。

從 Power BI 用戶端取得目前的服務主體設定檔

若要從 SDK 用戶端擷取目前的服務主體設定檔,請呼叫 GetServicePrincipalProfileObjectId

var profileObjectId = new Guid("81f24a6d-7ebb-4478-99c7-2c36f7870a26"); 
var powerBIclient = new PowerBIClient(credentials, profileObjectId: profileObjectId); 
var currentProfileObjectId = powerBIclient.GetServicePrincipalProfileObjectId(); 

考量與限制

在即時連線模式中,不支援使用 Azure Analysis Services (AAS) 的服務主體設定檔。