Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在不使用浏览器的情况下授权同一个google API_Python_Google Api_Google Bigquery_Google Drive Api_Google Sheets Api - Fatal编程技术网

Python 在不使用浏览器的情况下授权同一个google API

Python 在不使用浏览器的情况下授权同一个google API,python,google-api,google-bigquery,google-drive-api,google-sheets-api,Python,Google Api,Google Bigquery,Google Drive Api,Google Sheets Api,我有一个脚本,它必须从GoogleDrive、Bigquery中提取数据,然后通过管道将数据传输到GoogleSheets 我在没有浏览器的情况下成功地在Bigquery和Google sheets中进行了身份验证,但我找不到任何关于如何在Google Drive中进行身份验证的明确信息,更重要的是,如何以整洁的方式进行身份验证,以便存储服务帐户能够与这三个帐户一起工作 这是我为Bigquery所做的 import pandas_gbq from google.oauth2 import ser

我有一个脚本,它必须从GoogleDrive、Bigquery中提取数据,然后通过管道将数据传输到GoogleSheets

我在没有浏览器的情况下成功地在Bigquery和Google sheets中进行了身份验证,但我找不到任何关于如何在Google Drive中进行身份验证的明确信息,更重要的是,如何以整洁的方式进行身份验证,以便存储服务帐户能够与这三个帐户一起工作

这是我为Bigquery所做的

import pandas_gbq
from google.oauth2 import service_account

credentials = service_account.Credentials.from_service_account_info(
    {
        -InfoService account
  },
)
credentials = credentials.with_scopes(
    [
     'https://www.googleapis.com/auth/cloud-platform',
     'https://www.googleapis.com/auth/bigquery',
     'https://www.googleapis.com/auth/drive',
     ],
     )

sql = """sqlquery"""
df = pandas_gbq.read_gbq(sql, project_id=project_id, credentials=credentials)
对于谷歌表单

auth_key = {
  "client_id": "id",
  "client_secret": "secret",
  "refresh_token": "token"
}

credentials = client.OAuth2Credentials(
    access_token=None,
    client_id=auth_key['client_id'],
    client_secret=auth_key['client_secret'],
    refresh_token=auth_key['refresh_token'],
    token_expiry=None,
    token_uri=GOOGLE_TOKEN_URI,
    user_agent=None,
    revoke_uri=GOOGLE_REVOKE_URI)

credentials.refresh(httplib2.Http())
credentials.authorize(httplib2.Http())
cred = json.loads(credentials.to_json())
cred['type'] = 'authorized_user'

with open('adc.json', 'w') as outfile:
  json.dump(cred, outfile)

gauth = GoogleAuth()
gauth.credentials = credentials
client = gspread.authorize(gauth.credentials)

你能展示一下你试过的驱动器代码吗?您是否在中为同一服务帐户授权了它?我没有尝试使用驱动器,因为我找不到使用BQ或sheets的相同凭据的方法。在我看来,您正在寻找将服务帐户用于驱动器API的方法。你查过了吗?我相信这可能就是你想要的。让我知道!