如何修复Google Analytics(分析)用户删除API中的403:身份验证范围不足错误

问题描述 投票:0回答:1

调用Google Analytics(分析)user deletion API时出现以下错误

错误

HttpError:https://www.googleapis.com/analytics/v3/management/accounts/5795821/entityUserLinks/%27785972698.1540375322%27?返回“权限不足:请求的身份验证范围不足。“>

代码:

import csv
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials


def get_service(api_name, api_version, scope, key_file_location):
    credentials = ServiceAccountCredentials.from_json_keyfile_name(key_file_location,scope)      
    #Build the service object.
    service = build(api_name, api_version, credentials=credentials)
    return service


# open a list of client ids
with open('File_name.csv', 'rt') as csvfile:
    reader = csv.reader(csvfile, dialect='excel')
    reader_list = list(reader)

def delete_users(service):
    for row in reader_list:
        for row in reader_list:
            service.management().accountUserLinks().delete(
            accountId ='XXXXXX', 
            linkId = row[0]
            ).execute()

def main():
    # Define the auth scopes to request.
    scope = ['https://www.googleapis.com/auth/analytics.user.deletion']
    key_file_location = 'credentials.json'

    # Authenticate and construct service.
    service = get_service('analytics', 'v3', scope, key_file_location)
    delete_users(service)


if __name__ == '__main__':
    main()

我已经从GCP控制台下载了凭据文件>服务帐户并正在使用该帐户。无法了解确切原因是什么以及如何解决。在哪里可以看到/定义身份验证范围?任何文档或帮助将不胜感激。

我什至尝试根据this post在帐户ID的位置发送ViewId,但存在相同的错误。

对Google文档感到非常失望。

python api google-cloud-platform google-analytics google-analytics-api
1个回答
0
投票
权限不足:请求的身份验证范围不足。

完全是指用户无权执行您要尝试执行的操作。

转到Google Analytics(分析)网站,找到您要删除的视图所在的帐户。在帐户级别将服务帐户添加为用户。

然后它将有权访问该帐户。

© www.soinside.com 2019 - 2024. All rights reserved.