Skip to main content

Hi everyone,

 

I need to get page-based user view counts using the Python rest api. Can you support me on this issue?

2 respuestas
  1. 25 sept 2024, 16:53

    @Serkan Arslan​ 

    Hi, in this case you may use Tableau Server Client:

    import tableauserverclient as TSC

    import csv

     

    # server admin creds

    HOST = "https://prod-useast-b.online.tableau.com/"

    TOKEN_NAME = "Test"

    TOKEN_VALUE = "cjcvCg==:45pE9"

    CONTENT_URL = "yoursite"

     

    tableau_auth = TSC.PersonalAccessTokenAuth(TOKEN_NAME, TOKEN_VALUE, site_id=CONTENT_URL)

    server = TSC.Server(HOST, use_server_version=True)

     

     

    #Create the csv file and open it in write mode

    f = open('views.csv', 'w', encoding='UTF8', newline='')

     

    #delimiter with semicolon if need change to comma, and write header

    writer = csv.writer(f, delimiter=";")

    header = ['content URL','name','Owner_id','total_views']

    writer.writerow(header)

     

    today_date = datetime.now(timezone.utc)

     

    with server.auth.sign_in(tableau_auth):

    for view in TSC.Pager(server.views,usage=True):

    row=[view.content_url,view.name,view.owner_id,view.total_views]

    #print(view.conten_url,view.name,view.owner_id,view.total_views)

    #write the row

    writer.writerow(row)

    #Close file connection and sign out

    f.close()

    server.auth.sign_out()

    To use this code, you will need a PAT:

    https://help.tableau.com/current/pro/desktop/en-us/useracct.htm#create-a-personal-access-token

     

    If this post resolves the question, would you be so kind to "Select as Best"?. This will help other users find the same answer/resolution and help community keep track of answered questions. Thank you.

     

    Regards,

     

    Diego Martinez

    Tableau Visionary and Forums Ambassador

0/9000