从 Google Glass 获取 callbackURL 端点的 “回复” 通知

一位开发者正在尝试修改 “mirror-quick-start” Google Glass Mirror API 示例,以响应用户“回复”操作。他能够使用该示例显示一个可操作的卡片,其中内置“回复”操作。他希望用户能够通过读取科学仪器的数据来回复,然后他能够绘制数据并返回一个卡片给用户。然而,他遇到了一个问题:如何获取用户“回复”的值。
在这里插入图片描述

2、解决方案

1. 订阅时间线

def _insert_a600_subscription(self):
    """Attempt to register to a600 updates"""
    subscription = {
        "collection" : 'timeline',
        "userToken" : self.userid,
        "callbackUrl":"https://myapp_on_appengine.appspot.com/logA600",
    }
    try:
        self.mirror_service.subscriptions().insert(body=subscription).execute()
        logging.info("SUBSCRIBED")
    except errors.HttpError, error:
        print 'An error occurred: %s' % e

2. 插入带操作的项目

def _insert_item_with_action(self):
    """Insert a timeline item user can reply to."""
    logging.info('Inserting timeline item')
    body = {
        'creator': {
            'displayName': 'Python Starter Project',
            'id': 'PYTHON_STARTER_PROJECT'
        },
        'text': 'A600 at current time:',
        'id':'a600val',
        'notification': {'level': 'DEFAULT'},
        'menuItems': [{'action': 'REPLY',
                      }],
    }
    # self.mirror_service is initialized in util.auth_required.
    self.mirror_service.timeline().insert(body=body).execute()
    return 'A timeline item with action has been inserted.'

3. 创建用于处理 callbackURL 端点的请求处理程序

class A600Handler(webapp2.RequestHandler):

    @util.auth_required
    def post(self):
        """Process the value of A600 received and return a plot"""
        logging.info("Received POST to logA600")

    @util.auth_required
    def get(self):
        """Process the value of A600 received and return a plot"""
        logging.info("Received GET to this logA600")

MAIN_ROUTES = [
    ('/', MainHandler),('/logA600',A600Handler),
]

4. 从 callbackURL 端点接收通知

当用户对时间线卡片进行回复时,Google Glass 将向 callbackURL 端点发送一个 POST 请求。该请求将包含有关回复的信息,例如回复的文本和其他相关数据。

5. 处理收到的通知

收到通知后,开发者就可以处理回复的值,并根据需要采取相应的操作。例如,他可以将回复的值保存到数据库,或者将其可视化并以卡片的形式返回给用户。

6. 移出 @util.auth_required 装饰器

class A600Handler(webapp2.RequestHandler):

    def post(self):
        """Process the value of A600 received and return a plot"""
        logging.info("Received POST to logA600")

    def get(self):
        """Process the value of A600 received and return a plot"""
        logging.info("Received GET to this logA600")

MAIN_ROUTES = [
    ('/', MainHandler),('/logA600',A600Handler),
]

7. 测试

通过以上步骤,开发者就可以收到来自 Google Glass 的“回复”通知,并根据需要进行处理。为了测试,他可以将卡片发送到自己的 Glass 设备,进行回复,并检查是否能够在 callbackURL 端点收到通知。

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值