问题
Can someone spot what is wrong? the callback url is a valid ssl url. Also how do we know if google service itself is having issues? I don't yet see posts to my callback url at all on my web server logs..
I don't seem to be getting notifications back.
StoredCredentialsDBContext db = new StoredCredentialsDBContext();
TimelineItem item = new TimelineItem()
{
Creator=new Contact(){DisplayName="DLN Reply Card",Id="TESTREPLYCARD" },
Title = Test Number",
Text = "Say Test Number",
Notification = new NotificationConfig() { Level = "DEFAULT" }
};
Google.Apis.Mirror.v1.Data.MenuItem menuItem=new Google.Apis.Mirror.v1.Data.MenuItem();
menuItem.Action="REPLY";
item.MenuItems = new List<Google.Apis.Mirror.v1.Data.MenuItem>();
item.MenuItems.Add(menuItem);
foreach (StoredCredentials creds in db.StoredCredentialSet)
{
AuthorizationState state = new AuthorizationState()
{
AccessToken = creds.AccessToken,
RefreshToken = creds.RefreshToken
};
MirrorService service = new MirrorService(new BaseClientService.Initializer()
{
Authenticator = Utils.GetAuthenticatorFromState(state)
});
item.IsPinned = true;
Subscription subscription = new Subscription();
subscription.Collection = "timeline";
subscription.VerifyToken = "XXXXX";
subscription.UserToken = creds.UserId;
subscription.Operation = new List<String>();
subscription.Operation.Add("INSERT");
subscription.Operation.Add("UPDATE");
subscription.CallbackUrl = "https://changedthename.com/GG/Notify";
Subscription t=service.Subscriptions.Insert(subscription).Fetch();
TimelineItem i=service.Timeline.Insert(item).Fetch();
SubscriptionsListResponse r= service.Subscriptions.List().Fetch();
}
The output of executing Fetch() which is subscription object (I just hid the domain name):
?t
{Google.Apis.Mirror.v1.Data.Subscription}
CallbackUrl: "https://changedname.com/GG/Notify"
Collection: "timeline"
ETag: null
Id: "timeline"
Kind: "mirror#subscription"
Notification: null
Operation: Count = 2
Updated: "2014-02-06T16:59:25.642Z"
UserToken: "XXXXXXXXXX"
VerifyToken: "XXXXX"
Item I used:
?i
{Google.Apis.Mirror.v1.Data.TimelineItem}
Attachments: null
BundleId: null
CanonicalUrl: null
Created: "2014-02-06T16:59:32.729Z"
Creator: {Google.Apis.Mirror.v1.Data.Contact}
DisplayTime: null
ETag: "1391705972729"
Html: null
HtmlPages: null
Id: "73b75493-3371-4b2c-856d-df8674b54ede"
InReplyTo: null
IsBundleCover: null
IsDeleted: null
IsPinned: false
Kind: "mirror#timelineItem"
Location: null
MenuItems: Count = 1
Notification: {Google.Apis.Mirror.v1.Data.NotificationConfig}
PinScore: null
Recipients: null
SelfLink: "https://www.googleapis.com/mirror/v1/timeline/73b75493-3371-4b2c-856d-df8674b54ede"
SourceItemId: null
SpeakableText: null
Text: "Say Test Number"
Title: "Test Number"
Updated: "2014-02-06T16:59:32.729Z"
?r
{Google.Apis.Mirror.v1.Data.SubscriptionsListResponse}
ETag: null
Items: Count = 1
Kind: "mirror#subscriptionsList"
My Test payload for my callback url using SOapui
Post req with following payload
{
"collection": "timeline",
"itemId": "d45fcc3a-4346-453a-8783-88667a002387",
"operation": "UPDATE",
"userToken": "XXXXXXX",
"verifyToken": "XXXXX",
"userActions": [
{
"type": "<TYPE>",
"payload": "<PAYLOAD>"
}
]
}
200 ok response back from soapui
HTTP/1.1 200 OK
Cache-Control: private
Server: Microsoft-IIS/7.5
X-AspNetMvc-Version: 3.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 04 Feb 2014 17:48:47 GMT
Content-Length: 0
回答1:
I'm making a couple of assumptions:
You are seeing the cards posted to your Glass.
You're using .NET
Offhand, I'm not aware of any way to make sure the Mirror service is working correctly - but every time I've suspected a problem with it, it has turned out to be my service. A few things to try:
Make sure your callback URL actually works, accepts POST commands, and responds with HTTP code 200. You're correctly using HTTPS, but make sure you can get to the site using curl or wget with a POST operation, not just a GET operation. Test it from a machine outside the domain you're on to make sure the hostname is being looked up correctly and that you're not being blocked by firewalls.
You may want to do the subscription before you add the timeline item - best practice is to issue the subscription once when the person first logs in. I don't think this is it, but I can see it as possible that the subscription ends up not being applied correctly for some reason.
Test to make sure the Item and Subscription are correctly entered on the server - examine what is returned by both commands to make sure they are correct or issue a service.Subscriptions.List().Fetch() and examine the results.
Update: Based on what you've posted as the results of the Subscription.Insert().Fetch(), something seems odd there. The ETag and Id should certainly NOT be null. Something seems incorrect about about the Subscription insert attempt.
You may want to try a Subscriptions.List().Fetch() and see if there are any subscriptions actually registered.
Update 2: I would still suggest you do one, or both, of the following:
Replace your subscription code with the code provided in the .NET example at https://developers.google.com/glass/v1/reference/subscriptions/insert#examples and call it. I don't know enough about .NET, but there may be a reason your code is causing problems, since it appears that you the result of the Fetch() call is not a valid Subscription.
Implement the method in the .NET example at https://developers.google.com/glass/v1/reference/subscriptions/list#examples and call it after you do the create. If no subscription is listed, this is further indication you are not creating it for some reason.
来源:https://stackoverflow.com/questions/21529792/google-glass-not-receving-subscription-notifications