要在本地服务器上集成Power BI报告,可以使用Power BI的REST API和Power BI嵌入式功能。以下是一个解决方案,包含代码示例:
import requests
client_id = "YOUR_CLIENT_ID"
client_secret = "YOUR_CLIENT_SECRET"
resource = "https://analysis.windows.net/powerbi/api"
username = "YOUR_USERNAME"
password = "YOUR_PASSWORD"
data = {
'grant_type': 'password',
'scope': 'openid',
'resource': resource,
'client_id': client_id,
'client_secret': client_secret,
'username': username,
'password': password
}
response = requests.post('https://login.microsoftonline.com/common/oauth2/token', data=data)
access_token = response.json()['access_token']
groupId = "YOUR_GROUP_ID" # 报告所在的工作区组ID
reportId = "YOUR_REPORT_ID" # 报告的ID
headers = {
'Authorization': f'Bearer {access_token}'
}
response = requests.post(f'https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports/{reportId}/GenerateToken', headers=headers)
embed_token = response.json()['token']
Power BI Embedded Report
将上述代码示例中的“YOUR_CLIENT_ID”、“YOUR_CLIENT_SECRET”、“YOUR_USERNAME”、“YOUR_PASSWORD”、“YOUR_GROUP_ID”和“YOUR_REPORT_ID”替换为您自己的值。
这是一个基本的解决方案,用于在本地服务器上集成Power BI报告。您可以根据自己的需求进行修改和扩展。