使用文檔的https://developers.google.com/admin-sdk/directory/v1/guides/push#creating-notification-channels我使用類似訂閱通知:試圖阻止谷歌目錄API推送通知與客戶端返回404
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">
有趣的是,使用相同的參數(已知良好的「身份證'和'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月9日:
使用以下代碼試過的手動請求:
# '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月9日:
感謝@ Mr.Rebot您指出的報告API錯誤報告。 經過仔細檢查,這裏的問題完全一樣。 使用上面的手動請求代碼,但用下劃線調整URI,我終於能夠做出成功的請求(返回204)。
url = 'https://www.googleapis.com/admin/directory_v1/channels/stop'
所以肯定有某個地方的錯誤和下面的文檔頁有錯誤的端點URI:
- https://developers.google.com/admin-sdk/directory/v1/guides/push#stopping-notifications
- https://developers.google.com/admin-sdk/directory/v1/reference/channels/stop
也發現了這個相關的帖子:Google Admin SDK Channel Stop endpoint is broken in client libraries
我同意聽起來像一個錯誤。喜歡聽到您在手動通話中找到的內容。 – DaImTo
您可能想要查看[方法在文檔中顯示的URL不正確](https://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=3914)他們在Admin SDK中調試這類問題。這裏是相關的[SO問題](http://stackoverflow.com/a/31839251/5995040)報告。我同意@DaImTo,如果您能夠提供手動通話的結果,那將是非常好的。 –
對不起,最近幾天我病了。我編輯帖子以添加手動請求。仍然得到404。 –