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

前端 未结 2 1955
情书的邮戳
情书的邮戳 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:02

    According to this documentation, the scope that you're using requires Oauth 2.0 authorization. Therefore, a user login and consent is required.

    0 讨论(0)
  • 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', [])
    
    0 讨论(0)
提交回复
热议问题