def call_powerbi(self): # you might need to change these, but i doubt it authority_url = 'https://login.windows.net/common' resource_url = 'https://analysis.windows.net/powerbi/api' api_url = 'https://api.powerbi.com' # change these to your credentials client_id = '871c010f-5e61-4fb1-83ac-98610a7e9110' username = '******' password = '******' #假,資料移轉時請改輸入正確密碼,或由下一家提供 # first you need to authenticate using adal context = adal.AuthenticationContext(authority=authority_url, validate_authority=True, api_version=None) # get your authentication token token = context.acquire_token_with_username_password( resource=resource_url, client_id=client_id, username=username, password=password) # create your powerbi api client client = PowerBIClient(api_url, token) # create your columns columns = [] columns.append(Column(name='id', data_type='Int64')) columns.append(Column(name='name', data_type='string')) columns.append(Column(name='is_interesting', data_type='boolean')) columns.append(Column(name='cost_usd', data_type='double')) columns.append(Column(name='purchase_date', data_type='datetime')) # create your tables tables = [] tables.append(Table(name='AnExampleTableName', columns=columns)) # create your dataset dataset = Dataset(name='AnExampleDatasetName', tables=tables) # post your dataset! client.datasets.post_dataset(dataset) return
api_version=None) # In[5]: token = context.acquire_token_with_username_password(resource=resource_url, client_id=client_id, username=username, password=password) # In[6]: client = PowerBIClient(api_url, token) print("Client Initialized") # In[7]: def refresh_dataset(client_obj, dataset_id, notify_option=None, group_id=None): """ Refreshes a single dataset :param dataset_id: The id of the dataset to refresh :param notify_option: The optional notify_option to add in the request body :param group_id: The optional id of the group """ client = client_obj
import adal from pypowerbi.dataset import Column, Table, Dataset from pypowerbi.client import PowerBIClient from Credentials import client_id, username, password # Dataset to get refresh history for group_id = "<your dataset's group id>" dataset_id = "<your dataset's report id>" # create your powerbi api client client = PowerBIClient.get_client_with_username_password(client_id=client_id, username=username, password=password) # Get the entire refresh history history = client.datasets.get_dataset_refresh_history(dataset_id, group_id=group_id) print(history) # Get the most recent refresh history = client.datasets.get_dataset_refresh_history(dataset_id, group_id=group_id, top=1) print(history)