具有oauth2client(Python)的('Unexpected credentials type',None','Expected','service_account')

2024-04-30 04:46:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图用这个指南获取谷歌分析数据:https://ga-dev-tools.appspot.com/embed-api/server-side-authorization/

def get_access_token(request):
    return {'access_t': ServiceAccountCredentials.from_json_keyfile_name(
        KEY_FILEPATH, SCOPE).get_access_token().access_token }

使用上面的代码,我试图创建一个函数并将访问令牌返回到我的管理模板中的上下文。

然而。我知道这个错误我不知道该怎么办:

('Unexpected credentials type', None, 'Expected', 'service_account')

有什么问题吗?


Tags: 数据httpsdevcomtokenapigetaccess
2条回答

它看起来像google api python客户端中的示例

google-api-python-client/tree/master/samples/analytics

我也是这么想的。在我的例子中,修复方法是使用正确的json文件。我需要使用创建服务帐户密钥时保存的密钥,而不是使用服务帐户客户端的密钥:

developer console API key interface

希望能有帮助!

相关问题 更多 >