0

我一直在阅读https://powerbi.microsoft.com/en-us/blog/announcing-data-refresh-apis-in-the-power-bi-service/

在这篇文章中,它提到“要获取组 ID 和数据集 ID,您可以进行单独的 API 调用”。

有人知道如何从仪表板 URL 执行此操作,还是我必须在仪表板 URL 旁边的应用程序中嵌入组 ID 和数据集 ID?

4

2 回答 2

1

要获取组 ID 和数据集 ID,您可以进行单独的 API 调用。

这句话与仪表板无关,因为在一个仪表板中,您可以放置​​显示来自许多不同数据集的数据的视觉效果。这些不同的 API 调用是Get Groups(获取组列表,找到您想要的组并读取它的 id)和Get Datasets In Group(查找您正在寻找的数据集并读取它的 id)。

但无论如何,您应该已经知道 groupId,因为仪表板在同一个组中。

最终,您可以使用Get Tiles In Group从特定磁贴中获取 datasetId ,但我不知道使用 Rest API 在仪表板中列出磁贴的方法。

于 2018-12-18T15:23:18.860 回答
0

这是从 Power BI 获取数据集 ID 的 C# 项目代码。

使用以下方法调用“获取”API 并获取数据集 ID。


     public void GetDatasetDetails()
        {
            HttpResponseMessage response = null;
            HttpContent responseContent = null;
            string strContent = "";

            PowerBIDataset ds = null;         



            string serviceURL = "https://api.powerbi.com/v1.0/myorg/admin/datasets";


            Console.WriteLine("");
            Console.WriteLine("- Retrieving data from: " + serviceURL);

            response = client.GetAsync(serviceURL).Result;


            Console.WriteLine("   - Response code received: " + response.StatusCode);


            try
            {
                responseContent = response.Content;
                strContent = responseContent.ReadAsStringAsync().Result;

                if (strContent.Length > 0)
                {
                    Console.WriteLine("   - De-serializing DataSet details...");

                    // Parse the JSON string into objects and store in DataTable
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    js.MaxJsonLength = 2147483647;  // Set the maximum json document size to the max
                    ds = js.Deserialize<PowerBIDataset>(strContent);

                    if (ds != null)
                    {
                        if (ds.value != null)
                        {

                            foreach (PowerBIDatasetValue item in ds.value)
                            {
                                string datasetID = "";
                                string datasetName = "";
                                string datasetWeburl = "";



                                if (item.id != null)
                                {
                                    datasetID = item.id;
                                }

                                if (item.name != null)
                                {
                                    datasetName = item.name;
                                }

                                if (item.qnaEmbedURL != null)
                                {
                                    datasetWeburl = item.qnaEmbedURL;
                                }


                                // Output the dataset Data
                                Console.WriteLine("");
                                Console.WriteLine("----------------------------------------------------------------------------------");
                                Console.WriteLine("");
                                Console.WriteLine("Dataset ID: " + datasetID);
                                Console.WriteLine("Dataset Name: " + datasetName);
                                Console.WriteLine("Dataset Web Url: " + datasetWeburl);


                            } // foreach
                        } // ds.value
                    } // ds

                }
                else
                {
                    Console.WriteLine("   - No content received.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("   - API Access Error: " + ex.ToString());
            }
        }

要记住的要点:

  1. 确保这些类存在于您的项目中

PowerBIDataset 是一个具有 List 的类 PowerBIDatasetValue 是一个具有 id、name 和 webUrl(所有字符串数据类型)数据成员的类

  1. 在您的项目类中提供以下常量

常量字符串 ApplicationID = "747d78cd-xxxx-xxxx-xxxx-xxxx"; // 原生 Azure AD 应用 ClientID -- 将您的客户端 ID 放在这里

常量字符串用户名 = "user2@xxxxxxxxxxxx.onmicrosoft.com";
// 将您的 Active Directory / Power BI 用户名放在此处(请注意,这不是一个安全的存储位置!)

常量字符串密码=“xyxxyx”;
// 将您的 Active Directory / Power BI 密码放在这里(请注意,这不是安全的存储方式!这只是一个示例)

  1. 在项目类的 Main 方法中调用此 GetDatasetDetails() 方法

  2. 最后

使用下面的“获取”API 来获取组 ID

https://api.powerbi.com/v1.0/myorg/groups

于 2020-05-08T16:31:09.107 回答