【问题标题】:Trying to stop Google Directory API push notifications with a client returns 404尝试使用客户端停止 Google Directory API 推送通知会返回 404
【发布时间】:2017-03-16 11:35:03
【问题描述】:

使用https://developers.google.com/admin-sdk/directory/v1/guides/push#creating-notification-channels 的文档,我订阅了一个通知,使用类似:

service = build('admin', 'directory_v1', credentials=credentials)
watch_data = {
    'id': str(uuid.uuid1()),
    'type': 'web_hook',
    'address': 'https://example.appspot.com/push/user',
    'payload': True,
}
subscription = service.users().watch(domain=domain, event='update', body=watch_data).execute()
# 'subscription' is stored

我得到了正确的答复,到目前为止一切似乎都很好。

直到我尝试使用以下代码停止通知:

# 'subscription' is retrieved from the storage
service = build('admin', 'directory_v1', credentials=credentials)
stop_data = {
    'id': subscription.id,
    'resourceId': subscription.resource_id
}
request = service.channels().stop(body=stop_data)
request.execute()

这会引发 'HttpError' 404 异常:

Response: <HttpError 404 when requesting https://www.googleapis.com/admin/directory/v1/admin/directory_v1/channels/stop? returned "Not Found">

有趣的是,使用相同的参数(来自同一用户的已知良好的“id”和“resourceId”),https://developers.google.com/admin-sdk/directory/v1/reference/channels/stop 的 API 浏览器小工具以相同的方式失败。

我也无法在完整的 API 资源管理器中找到此端点。

我认为这个发现有些不正常。

客户端构建的URI是:'https://www.googleapis.com/admin/directory/v1/admin/directory_v1/channels/stop'
而文档说明它应该是:
'https://www.googleapis.com/admin/directory/v1/channels/stop'。

这可能是 API 中的错误吗?

我将尝试尽快发出“手动”身份验证请求以检查此假设。

编辑 2016-11-09:

使用以下代码尝试手动请求:

# 'subscription' is retrieved from the storage
stop_data = {
    'id': subscription.id,
    'resourceId': subscription.resource_id
}
http = httplib2.Http()
http = credentials.authorize(http)
url = 'https://www.googleapis.com/admin/directory/v1/channels/stop'
method = 'POST'
response, content = http.request(url, method, body=json.dumps(stop_data),
                                 headers={'content-type': 'application/json'})

我仍然得到一个 404 结果。所以我猜问题不在于端点 URI。

如果 Google 的某个人读到了这篇文章,您能查一下吗?

这不是超级关键,但我不想有悬空的通知订阅。

编辑 2 2016-11-09:

感谢 @Mr.Rebot 指出报告 API 错误报告。 仔细观察,这里的问题是完全一样的。 使用上面的手动请求代码,但使用下划线调整 URI,我终于能够成功请求(返回 204)。

url = 'https://www.googleapis.com/admin/directory_v1/channels/stop'

因此,某处肯定存在错误,并且以下文档页面的端点 URI 错误:

还发现了这个相关的帖子:Google Admin SDK Channel Stop endpoint is broken in client libraries

【问题讨论】:

  • 我同意这听起来像是一个错误。喜欢听听您在手动呼叫中找到的内容。
  • 您可能想查看methods show incorrect URL in documentation,了解他们如何在 Admin SDK 中调试此类问题。这是报告的相关SO question。我同意@DaImTo,如果您能够提供手动调用的结果,那就太好了。
  • 抱歉回复晚了,这几天生病了。我编辑了帖子以添加手动请求。仍然得到 404。

标签: google-api google-admin-sdk google-api-python-client google-directory-api


【解决方案1】:

致那些在过去两年里在 Google Docs 地狱中创造奇迹的人,而且还在不断增加。

错误/正确的网址是:

https://www.googleapis.com/admin/reports_v1/channels/stop

而使用这个网址的范围是:

https://www.googleapis.com/auth/admin.reports.audit.readonly

我希望这对某人有帮助:)

【讨论】:

    猜你喜欢
    • 2013-11-08
    • 2017-07-25
    • 2019-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多