2
votes

I have created a timeline card with a custom menu item. I would like to get a callback when the user has selected that menu item.

// Create a menu item for the card
var mnuActivate = new MenuItem() {
    Action = "CUSTOM",
    RemoveWhenSelected = new bool?(true),
    Id = ACCEPT_ID,
    Values = new List<MenuValue>() {
        new MenuValue() {
            State="DEFAULT",
            DisplayName="Activate",
        },
        new MenuValue() {
            State="PENDING",
            DisplayName="Activating..."
        },
        new MenuValue() {
            State="CONFIRMED",
            DisplayName="Activated"
        }
    }
}

// Create a new card for the user's timeline
var item = new TimelineItem() {
    Html = html,
    Notification = new NotificationConfig() { Level = "DEFAULT" },
    MenuItems = new List<MenuItem>() { mnuActivate }
};

var card = this._service.Timeline.Insert(item).Fetch();

I then subscribe to all timeline events and provide an https callback URL

 // Create a new subscription
var subscription = new Subscription()
{
    Collection = "timeline",
    Operation = new List(),
    CallbackUrl = "https://mypubliclyavailableserver.com/notify"
};
this._service.Subscriptions.Insert(subscription).Fetch();
// Retrieve a list of subscriptions to make sure it is there.
var mySubcriptions = this._service.Subscriptions.List().Fetch();
if (mySubcriptions != null && mySubcriptions.Items != null && mySubcriptions.Items.Count == 1)
{
    Console.WriteLine("Subscription created successfully.");
}
So the subscription is created without any issues as far as I can tell. But after interacting with the card, I never get a callback. What am I missing?

Things I have tried:

  1. Populating Ids on the subscription obj, timeline card, and menuItem
  2. Subscribing before creating the card instead of after
  3. Adding the userId as the UserToken on the subscription object
  4. Calling my callback URL directly to ensure that it is listening

JSON Response from GET /mirror/v1/subscriptions:

{
 "kind": "mirror#subscriptionsList",
 "items": [
  {
   "kind": "mirror#subscription",
   "id": "timeline",
   "updated": "2013-10-28T15:19:19.404Z",
   "collection": "timeline",
   "callbackUrl": "https://mypubliclyavailableserver.com/notify"
  }
 ]
}
3
If you GET the subscription, what is the json returned? - mimming
Hmmm, I wonder if the problem could be Operation = new List() as opposed to Operation = null ... - Scarygami
@Scarygami, I've tried that as well. - Software.Developer

3 Answers

0
votes

I am not an expert on this subject. But searching for the same topic, I found this https://developers.google.com/glass/subscription-proxy, according to this, don't you need to have the forward url? I think the callback url format is not right in your example?

0
votes

Have you tried without the "operation" all together.

var subscription = new Subscription() { Collection = "timeline", CallbackUrl = "https://mypubliclyavailableserver.com/notify" }

It's an optional https://developers.google.com/glass/v1/reference/subscriptions/insert

0
votes

It turns out there was a problem with my SSL certificate at my callback URL https://mypubliclyavailableserver.com/notify

It worked when I tried to hit my webservice from hackst.com. I guess they ignored the "Could not establish trust relationship for SSL/TLS secure channel" error that Google was seeing.

There is no location which Google can send the error, so I just never knew whether it was calling me or not. Perhaps if during the subscription process, if the callback URL's cert does not appear valid, an error could be returned?