4

I am trying to modify the "mirror-quick-start" Google Glass Mirror API example to respond to a user "REPLY" action.

I am able to display an actionable card using the example with the REPLY built in action.

I want the user to be able to reply with a reading off a scientific instrument, which I want to be able to plot and return a card back to the user.

I am however stuck at step zero. How to get the value the user "Replied" with.

Here is my attempt at subscribing to the timeline. I can get the "SUBSCRIBED" message in my appengine log.

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

The card that I generate is based off the example.

  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.'

I also created a "dummy" handler for the callbackUrl endopoint "logA600" as follows.

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), ]

When I reply to the timeline card . My logs never show a POST received to my handler with the expected message "Received POST to logA600" ..instead I get the following in my appengine logs.

2013-07-15 19:52:43.913 /logA600 302 37ms 0kb GlassAPI XX.XXX.XX.XX - - [15/Jul/2013:16:52:43 -0700] "POST /logA600 HTTP/1.1" 302 136 - "GlassAPI" "myapp_on_appengine.appspot.com" ms=37 cpu_ms=0 cpm_usd=0.000032 app_engine_release=1.8.2 instance=0XXXXXXXXXXXXXXXXXXXXXXXXd I 2013-07-15 19:52:43.889 URL being requested: https://www.googleapis.com/discovery/v1/apis/mirror/v1/rest?userIp=xx.xx.xx.xxx

At my test app. I can see the timeline card arrive successfully. I am looking for help on getting the "REPLY" notification "subscription" to my callbackUrl /logA600 handler.

J Wang
  • 2,075
  • 1
  • 20
  • 26
harijay
  • 11,303
  • 12
  • 38
  • 52

1 Answers1

4

Remove @util.auth_required before def post(self): in /logA600.

The reason this happens is because @util.auth_required checks to verify that the current user is authorized, and if they are not, it redirects them to your OAuth 2.0 flow initiation URL. Subscription notifications are not authorized requests. They come without any cookies as if they are an anonymous user. Seeing this, @util.auth_required is redirecting the notification to the auth page.

mimming
  • 13,974
  • 3
  • 45
  • 74
  • Thanks Jenny, Once I removed that decorator. I am now seeing the POST notification in my logs. Also, although my code example above did not use the subscription proxy server..I didnt realize it was not needed since the appengine URLs are "https" URLS. – harijay Jul 16 '13 at 01:30