简体   繁体   English

如何从Glass收到有关已选择自定义菜单项的通知?

[英]How to get a notification from Glass that a custom menu item was selected?

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 然后,我订阅所有时间轴事件并提供一个https回调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 在订阅obj,时间轴卡和menuItem上填充ID
  2. Subscribing before creating the card instead of after 在创建卡之前(而不是之后)订阅
  3. Adding the userId as the UserToken on the subscription object 在订阅对象上添加userId作为UserToken
  4. Calling my callback URL directly to ensure that it is listening 直接调用我的回调URL以确保它正在侦听

JSON Response from GET /mirror/v1/subscriptions: GET / mirror / v1 / subscriptions的JSON响应:

 { "kind": "mirror#subscriptionsList", "items": [ { "kind": "mirror#subscription", "id": "timeline", "updated": "2013-10-28T15:19:19.404Z", "collection": "timeline", "callbackUrl": "https://mypubliclyavailableserver.com/notify" } ] } 

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? 但是,在搜索同一主题时,我发现了这个https://developers.google.com/glass/subscription-proxy ,据此,您是否不需要转发URL? I think the callback url format is not right in your example? 我认为您的示例中的回调网址格式不正确?

Have you tried without the "operation" all together. 您是否尝试过全部不进行“操作”。

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

It's an optional https://developers.google.com/glass/v1/reference/subscriptions/insert 这是一个可选的https://developers.google.com/glass/v1/reference/subscriptions/insert

It turns out there was a problem with my SSL certificate at my callback URL https://mypubliclyavailableserver.com/notify 事实证明我的回调URL https://mypubliclyavailableserver.com/notify SSL证书有问题

It worked when I tried to hit my webservice from hackst.com. 当我尝试从hackst.com访问我的Web服务时,它起作用了。 I guess they ignored the "Could not establish trust relationship for SSL/TLS secure channel" error that Google was seeing. 我猜他们忽略了Google看到的“无法为SSL / TLS安全通道建立信任关系”错误。

There is no location which Google can send the error, so I just never knew whether it was calling me or not. Google没有可以发送错误的位置,因此我只是不知道它是否在打电话给我。 Perhaps if during the subscription process, if the callback URL's cert does not appear valid, an error could be returned? 也许在订阅过程中,如果回调URL的证书看起来无效,则可能返回错误?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM