2

This is the code I have so far where get_url is a helper function that wraps the url with the subscription proxy url that forwards the notifications to some dummy server I hate setup.

card = {
    'text': 'click ok',
    'menuItems': [{
                      'action': 'CUSTOM',
                      'id': 'ready',
                      'values': [{
                                     'displayName': 'o',
                                     'iconUrl': 'img.jpg'
                                 }]
                  }],
}
self.mirror_service.timeline().insert(body=card).execute()
callback_url = get_url(self, '/start')
body = { # self.userid is initialized in util.auth_required.
    'collection': self.request.get('collection', 'timeline'),
    'userToken': self.userid,
    'callbackUrl': callback_url
}

I confirmed that the subscription is created (using the list call) but when I click the menu item in the glass playground my proxy server isn't seeing any notify requests. Any tips?

mimming
  • 13,974
  • 3
  • 45
  • 74
rgrinberg
  • 9,638
  • 7
  • 27
  • 44

1 Answers1

2

It looks like your callback_url might want to be /notify instead of /start, but I can't be certain about that without access to all of your project.

Specifically about the Subscription proxy, the json example found at the documentation appears to be incomplete.

First, make sure you change the user token to a valid user token, which will be a series of numbers. Next, add in an itemId, and a userActions object. Here is the JSON that worked for me:

{
"callbackUrl": "https://mirrornotifications.appspot.com/forward?url=http://example.com/path/to/test.php",
"collection": "timeline",
"itemId": "your-item-id-here",
"operation": "UPDATE",
"userToken": "your-userToken-here",
"userActions": [
    {
        "type": "PIN"
    }
]

}

Make sure to replace itemId too. I got the userToken and itemId by looking at app engine logs, in my set up.

Here is some general advice for working on callbacks:

I can confirm that a properly set up custom subscription, will get a callback, when a user on Glass executes the action. If you are not seeing the callback in what appears to be your custom code, you might back up and try a starter project

I use Java and the App Engine starter project, and here are some things that helped me with that setup. It is useful to use log statements, deploy your app to app engine and then view those log statements in the app engine administrative console.

If you can see the log statements executing, (in my case code within NotifyServlet.java) then things are going well.

You can fine tune things locally at this point by using command line Curl to call your notify actions directly, simulating a callback request without the hassle of deploying to app engine or tapping on glass hardware.

Another benefit of this is that if you proxy your curl command through a packet sniffer like WireShark, Fiddler or Charles, you can easily view the http transaction and debug what is going on.

Good luck!

Mark Scheel
  • 2,963
  • 1
  • 20
  • 23
  • Thanks Mark, it looks like that was the issue. The deployed app did indeed fire off tifies to /notify. I'm aware that I need to use curl to simulate the requests but I thought that I would at least be able to see what kind of requests are generated by logging the http requests from their proxy. Have you gotten the proxy to work at all? – rgrinberg Jun 17 '13 at 03:13
  • I'm not sure what you mean by "their proxy", can you expand on that for me? – Mark Scheel Jun 17 '13 at 04:50
  • Yes, I got it to work. The documentation is not as clear as it could be, I'll update my answer to include some information about the JSON you should be sending to make it work. – Mark Scheel Jun 17 '13 at 13:43