Python中的gspread oauth2client服务帐户凭据

时间:2018-12-11 04:22:17

标签: python python-3.x google-oauth2 gspread

我正在尝试使用python 3.7.1中的gspread包访问google电子表格。我还创建了所需的凭据并定义了范围。我正在尝试通过仅以ServiceAccountCredentials.from_json_keyfile_name()消除service_account.ServiceAccountCredentials()来消除.json文件,如Oauth2的google groups thread所示。但是,我无法找出与.json文件中的参数匹配的参数。

下面是ServiceAccountCredentials()正在寻找的参数:

service_account_email
signer
scopes
private_key_id
client_id
user_agent
token_uri
revoke_uri
kwargs

以下是.json文件中可用的参数:

type
project_id
private_key_id
private_key
client_email
client_id
auth_uri
token_uri
auth_provider_x509_cert_url
client_x509_cert_url

下面是我当前拥有的代码:

# import required modules/packages
import gspread
from oauth2client.service_account import ServiceAccountCredentials

# Define scope
scopes = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']

# Validate credentials which works perfectly
credentials = ServiceAccountCredentials.from_json_keyfile_name('secret-key.json', scopes)

# Above line needs to be replaced by this:
credentials = service_account.ServiceAccountCredentials(
    service_account_email = client_email,
    signer = , # Need help
    scopes = scopes
    private_key_id = private_key_id,
    client_id = client_id,
    user_agent = , # Need help
    token_uri = token_uri,
    revoke_uri = , # Need help
    kwargs = # Need help
)

任何帮助,将不胜感激。

0 个答案:

没有答案