我设法通过 Python API iamcredetials.googleapis.com 创建了一个服务帐户和一个自身的密钥,但我无法登录它,因为密钥是 P12 格式并dict
以 .登录密钥。有没有办法创建 p12 文件或其他东西,以便我可以使用密钥?
我尝试使用模块中可用的函数,oauth2clinet.service_account.ServiceAccountCredentials()
但它们都没有成功加载它,我知道这个库中有一定程度的弃用,也许我正在使用过时的方法。
我越接近成功登录是在使用 _from_p12_keyfile_contents()
给出“编码例程”错误的功能时,这超出了我的理解。
from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient import discovery, errors, logging
default_creds = google_application_defaults()
service = discovery.build("iam", "v1", credentials=default_creds, cache_discovery = False)
key = service.projects().serviceAccounts().keys().create( name = serviceAccMail, body={}).execute()
creds = ServiceAccountCredentials._from_p12_keyfile_contents(accountEmail, newkey["privateKeyData"], "notasecret")
Error: [('asn1 encoding routines', 'asn1_check_tlen', 'wrong tag'), ('asn1 encoding routines', 'asn1_item_embed_d2i', 'nested asn1 error')]
登录此密钥的正确方法是什么?