How do I Authenticate a Service Account to Make Queries against a GDrive Sheet Backed BigQuery Table?

后端 未结 4 2047
野趣味
野趣味 2021-01-14 12:45

My situation is as follows:

Google Account A has some data in BigQuery.

Google Account B manages Account A\'s BigQuery data, and has also been given editor p

4条回答
  •  攒了一身酷
    2021-01-14 12:52

    You should be able to get this working with the following steps:

    First share the sheet with the email/"service account id" associated with the service account.

    Then you'll be able to access your sheet-backed table if you create a Client with the bigquery and drive scopes. (You might need to have domain-wide-delegation enabled on the service account).

    scopes = ['https://www.googleapis.com/auth/bigquery', 'https://www.googleapis.com/auth/drive']
    
    credentials = ServiceAccountCredentials.from_json_keyfile_name(
    '', scopes=scopes)
    
    # Instantiates a client
    client = bigquery.Client(project = PROJECT, credentials = credentials)
    
    bqQuery = client.run_sync_query(q)
    bqQuery.run()
    bqQuery.fetch_data()
    

提交回复
热议问题