首页 > 解决方案 > Google Admin Directory SDK中的用户观看功能,突然抛出错误参数投影异常

问题描述

我在 GCP 上有一个运行超过 18 个月的云功能。一周前突然停止工作。

编码

import googleapiclient.discovery
        
adminDirectoryService = googleapiclient.discovery.build('admin', 'directory_v1', credentials = gsuiteCredentials, cache_discovery=False)

result = adminDirectoryService.users().watch(body=watchBody, projection=projection, event=eventType, maxResults=1, customer=gSuiteCutomerId, viewType=viewType).execute()

    

例外

result = adminDirectoryService.users().watch(body=watchBody, projection=projection, event=eventType, maxResults=1, customer=gSuiteCutomerId, viewType=viewType).execute()
File "/env/lib/python3.7/site-packages/google_api_python_client-1.7.8-py3.7.egg/googleapiclient/discovery.py", line 723, in method
    raise TypeError('Got an unexpected keyword argument "%s"' % name)
TypeError: Got an unexpected keyword argument "projection"

我不知道是什么导致了这个问题。我已经检查了文档,它清楚地说明了这个projection论点存在。

还有其他人遇到这个问题吗?有什么建议么?

标签: pythongoogle-admin-sdkgoogle-directory-api

解决方案


以下解决了我的问题:我已从我的请求中删除了projectionmaxResultsviewType参数,并且一切正常。

对问题发生原因的一些解释。googleapiclient.discovery 基于提供给它的 JSON 构建 API。似乎 Google 更改了返回的 JSON,而没有向任何人说明这些制动更改。

JSON 可以在这里找到(对于admindirectory_v1

如果有人使用不同的版本或 API。我通过查看此处的发现代码找到了源代码。

我希望它会帮助其他人。

编辑

看来这个问题已经被谷歌解决了。不再需要此答案中的解决方法


推荐阅读