大佬教程收集整理的这篇文章主要介绍了私有 REST API 连接 Power BI (M - Power Query),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想将 powerbi 与客户端私有 Rest API 连接。所以,我一直在尝试用 M 编写代码以便做到这一点,但我不是 M 语言的专家。
这就是我尝试在 Power bi 中生成不记名令牌的方法。你能帮我写代码吗?
let
url = "https://openID-provIDer.crearesistemas.com.br/auth/v1/token?lang=pt-BR",body = "{ ""clIEnt_ID"": ""*****"",""clIEnt_secret"": ""*****"",""grant_type"": ""clIEnt_credentials""}",tokenResponse = Json.document(Web.Contents(url,[headers = [#"Authorization"="Basic Auth",#"Content-Type"="application/Json"
],Content = Text.ToBinary(body)
]
)),Accesstoken = tokenResponse[access_token],Accesstokenheader = "Bearer " & Accesstoken
in
Accesstokenheader
我不知道我做错了什么。 它显示以下错误:“Datasource.Error”“DatasourceKind=Web”“DatasourcePath=https://openID-provIDer.crearesistemas.com.br/auth/v1/token”
生成 Bearer Token 后,我必须使用“get 方法”才能从 API 请求客户端数据。
main_API_url: https://api.crearecloud.com.br/frotalog/basic-services/v3/ ...
授权:Bearer Token
Json格式
希望大家帮帮我!提前致谢。
如果您将文档链接到您尝试使用的端点会有所帮助,否则我们不确切知道您需要什么。您的目标是什么 http 请求?
我必须使用'get方法'
对于 GET
请求,您使用 Query
,对于 POST
,您使用 Content
。都接受type record
对于第 1 步,我认为您将这些参数作为 GET 请求请求。
如果您需要 POST,只需将 Query
替换为 Content
using the example
"GET" request and:
"https://openid-provider.crearesistemas.com.br/auth/v1/token?lang=pt-BR",{
"client_id": "*****","client_secret": "*****","grant_type": "client_credentials"
}
let
Headers = [
Accept="application/json",Authorization = "Basic Auth"
],BaseUrl = "https://openid-provider.crearesistemas.com.br",Options = [
RelativePath = "/auth/v1/token",Headers = Headers,Query = [
lang = "pt-BR",client_id = "id",client_secret = "secret",grant_type = "client_credentails"
],ManualStatusHandling = {400,404}
],// wrap 'Response' in 'Binary.buffer' if you are referencing it multiple times
response_binary = Web.Contents(BaseUrl,Options),buffered = Binary.buffer(response_binary),response_metadata = Value.Metadata(response_binary),status_code = response_metadata[Response.Status],// for 400 and 404,return extra error info
maybe_bytes =
if List.Contains({400,404},status_code)
then response_metadata else buffered,from_json = Json.Document(maybe_bytes)
// returns either document else web request error
in
from_json
查看更多:
Web.Contents
calls这就是我在为它制作 API 之前获取数据流刷新数据的方式。理想情况下,人们不会在查询中输入凭据。
let
APIString =" https://api.powerbi.com/v1.0/myorg/gr...",GetToken =
let
client_id = yourclientID,client_secret= yourclientsecret,redirect_uri = "http://localhost:13526/redirect",token_uri = "https://login.windows.net/common/oauth2/token",authorize_uri = "https://login.windows.net/common/oauth2/authorize",resource="https://analysis.windows.net/powerbi/api",username=yourusername,password=yourpassword,tokenResponse = Json.Document(Web.Contents(token_uri,[Content = Text.ToBinary(Uri.buildQueryString( [
client_id = client_id,client_secret=client_secret,username=username,password=password,resource=resource,grant_type = "password",redirect_uri = redirect_uri ])),Headers= [Accept="application/json"],ManualStatusHandling= {400} ])),access_token = tokenResponse[access_token],token = tokenResponse[access_token]
in
token,GetGroups = Json.Document(Web.Contents(APIString,[ Headers = [ Authorization="Bearer "& GetToken ],ManualStatusHandling={400} ] )),value = GetGroups[value],#"Converted to Table" = Table.FromList(value,Splitter.SplitByNothing(),null,ExtraValues.Error),#"Expanded column1" = Table.ExpandRecordcolumn(#"Converted to Table","column1",{"id","refreshType","startTime","endTime","status"},"status"}),#"Changed Type" = Table.TransformcolumnTypes(#"Expanded column1",{{"id",type text},{"refreshType",{"status",{"startTime",type datetiR_714_11845@ezonE},{"endTime",type datetiR_714_11845@ezonE}}),#"Changed Type1" = Table.TransformcolumnTypes(#"Changed Type",{{"endTime",type datetiR_714_11845@E},type datetiR_714_11845@E}})
in
#"Changed Type1"
以上是大佬教程为你收集整理的私有 REST API 连接 Power BI (M - Power Query)全部内容,希望文章能够帮你解决私有 REST API 连接 Power BI (M - Power Query)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。