【问题标题】:Invoking PowerBi rest api and generate token调用 PowerBi rest api 并生成令牌
【发布时间】:2021-09-23 12:01:26
【问题描述】:

我想调用 PowerBI rest api 调用以从本地/特定存储库上传 pbix 文件。

  • 我应该如何生成不记名令牌以供 Postman 授权?

  • 此 api 调用是否可以生成令牌?

  • 这个休息调用需要传递什么作为授权令牌?

  • myorg 是 PowerBI 帐户名吗?我可以从哪里获取 myorg 值?

     POST https://api.powerbi.com/v1.0/myorg/GenerateToken
    

下面是我想通过邮递员调用的几个调用:

GET https://api.powerbi.com/v1.0/myorg/imports
GET https://api.powerbi.com/v1.0/myorg/reports/{reportId}

而且也很少打电话。

生成令牌的快速解决方案是什么?

【问题讨论】:

    标签: powerbi postman rest powerbi-rest-api


    【解决方案1】:

    您可以使用此功能请求访问权限

    必须在 azure 中创建客户端 ID https://docs.microsoft.com/en-us/power-bi/developer/embedded/register-app?tabs=customers%2CAzure

        application_id= 'None'
        application_secret= 'None'
        user_id= 'None'
        user_password= 'None'
    
        accessToken = None 
        requestHeaders = None 
        tokenExpiry = None 
        accessToken_AD = None 
        requestHeaders_AD = None 
        tokenExpiry_AD = None 
    
         def pbi_auth(application_id,application_secret,user_id,user_password):
            global accessToken
            global requestHeaders
            global tokenExpiry
            data = {
                'grant_type': 'password',
                'scope': 'openid',
                'resource': "https://analysis.windows.net/powerbi/api",
                'client_id': application_id,
                'client_secret': application_secret,
                'username': user_id,
                'password': user_password
            }
            token = requests.post("https://login.microsoftonline.com/common/oauth2/token", data=data)
            assert token.status_code == 200, "Fail to retrieve token: {}".format(token.text)
            #print("Got access token: ")
            #print(token.json())
            accessToken = token.json()['access_token']
        
            requestHeaders= {
                'Content-Type': 'application/json; charset=utf-8',
                'Authorization': "Bearer {}".format(accessToken)
            }
    
        pbi_auth(application_id,application_secret,user_id,user_password)
        reportId= ""
        URI = "https://api.powerbi.com/v1.0/myorg/reports/{}".format(reportId)
        queryResults =  requests.get(URI, headers=requestHeaders)
    

    【讨论】:

      猜你喜欢
      • 2019-08-01
      • 2018-12-17
      • 1970-01-01
      • 1970-01-01
      • 2020-09-21
      • 2016-01-19
      • 2018-07-30
      • 1970-01-01
      • 2016-04-17
      相关资源
      最近更新 更多