Use Application Default Credentials on Google Compute Engine to access Sheets API

前端 未结 2 1984
情书的邮戳
情书的邮戳 2021-01-19 10:33

Does the ADC (Application Default Credentials) workflow only support Google Cloud APIs (for example, supports for Google Cloud Storage API, but not the Google Sheet API)?

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-19 11:04

    Credentials are optional for the build constructor. Omit them and the Cloud Function service account will be used to authenticate against the Sheet.

    from apiclient import discovery
    
    sheets = discovery.build('sheets', 'v4')
    
    SPREADSHEETID = '....'
    
    result = sheets.spreadsheets().values().get(spreadsheetId=SPREADSHEETID, range='Sheet1!A:B').execute()
    
    print result.get('values', [])
    

提交回复
热议问题