且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从 Power BI 中的服务检索不记名令牌?

更新时间:2023-02-24 12:34:28

Number-1:您可以根据自己的目的构建自己的数据连接器.一些指南可以在这里找到 - 点击这里

Number-1: You can build your own data connector for your purpose. Some guidelines will find here- Click Here

NUMber-2:您还可以使用电源查询来连接您的信号源.最近我使用 oAuth2 API 为客户收集了数据.您可以使用 Power/M Query 连接到任何 API.以下是我的案例的示例代码,在第一部分中,我收集了 access_token,在第二步中,我使用该访问令牌收集了数据.希望这能让您对使用 Power Query 连接到任何 API 有所了解.

NUmber-2: You can also use power query to connect your source. Recently I have collected data for clients using oAuth2 API. You can connect to any API using Power/M Query. Following is the sample code for my case, where in the first part I have collected the access_token and in second step, I have collected data using that access token. hope this will give you some idea on connecting to any API using Power Query.

let
    url = "your_authentication_url_here",

    body  = "{ ""client_id"": ""****"",  ""client_secret"": ""****"", ""grant_type"": ""****"", ""audience"":""****""}",
    tokenResponse = Json.Document(Web.Contents(url,[Headers = [#"Content-Type"="application/json"], Content = Text.ToBinary(body) ] )),
    AccessToken = tokenResponse[access_token],
    AccessTokenHeader = "Bearer " & AccessToken,


    data_url = "your_main_url_here",
    data_body = "{
                    ""authorization"": """& AccessTokenHeader & """,
                    ""content-type"": ""application/json""
                }",

    GetGroups = Json.Document(
        Web.Contents(
            data_url, 
            [
                Headers = Json.Document(data_body)
            ] 
        )
    ),    

    categories = GetGroups[categories], --Category here will be changed as per your retrned data

    #"Converted to Table" = Table.FromList(categories, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn
    (
        #"Converted to Table", "Column1", 
        {"ext_id", "shared", "report", "query", "_id", "description"}, --This is column returned from your data set
        {"ext_id", "shared", "report", "query", "_id", "description"}  -- Rename columns accordingly
    )
in
    #"Expanded Column1"