在我的pythonggae应用程序中,我在理解和实现googledirectoryapi的用户监视功能和推送通知系统(https://developers.google.com/admin-sdk/reports/v1/guides/push#creating-notification-channels)时遇到了一些困难。我试图实现的是,任何使用我的应用程序的用户(管理员)都可以在自己的域内监视用户的更改。在
我已经验证了要用于通知的域,并按如下方式实现了监视请求:
directoryauthdecorator = OAuth2Decorator(
approval_prompt='force',
client_id='my_client_id',
client_secret='my_client_secret',
callback_path='/oauth2callback',
scope=['https://www.googleapis.com/auth/admin.directory.user'])
class PushNotifications(webapp.RequestHandler):
@directoryauthdecorator.oauth_required
def get(self):
auth_http = directoryauthdecorator.http()
service = build("admin", "directory_v1", http=auth_http)
uu_id=str(uuid.uuid4())
param={}
param['customer']='my_customer'
param['event']='add'
param['body']={'type':'web_hook','id':uu_id,'address':'https://my-domain.com/pushNotifications'}
watchUsers = service.users().watch(**param).execute()
application = webapp.WSGIApplication(
[
('/pushNotifications',PushNotifications),
(directoryauthdecorator.callback_path, directoryauthdecorator.callback_handler())],
debug=True)
现在,接收部分是我不明白的。当我在我的域中添加用户并检查应用程序的请求日志时,我看到一些活动,但没有可用的数据。我该如何处理这一部分?在
任何帮助都将不胜感激。谢谢。在
设法弄明白了。在appengine日志中,我注意到,每次我在我的域上做一个被“监视”的更改时,都会收到一个来自Google API的POST请求,但代码是302。我发现这是因为我在
app.yaml
中为脚本配置了login: required
,该脚本正在处理请求,POST请求被重定向到登录页面,而不是处理脚本。在问题
似乎在实现处理程序时有些混乱。处理程序实际上通过向Reports API端点发送POST请求来设置通知通道。就像医生说的:
source
你只需要发送这个请求一次就可以设置频道,“address”参数应该是应用程序上接收通知的URL。在
此外,还不清楚以下代码发生了什么:
你只是为了把它贴在这里而破坏代码吗?或者它实际上是这样写在文件中的?实际上,你应该尽可能地保存你的应用程序正在运行的代码,这样我们就可以对它进行推理了。在
解决方案
从您链接的文档来看,在“Receiving Notifications”部分中,您应该在“address”中指定代码来接收通知,这些通知将检查POST请求的主体和通知推送请求的头,然后对该数据执行某些操作(如将其存储在BigQuery中或向管理员发送电子邮件等)
相关问题 更多 >
编程相关推荐