I downloaded the PHP quickstart from google ( link ) and put it online on a secure site.
When subscribing to timeline events, the file notify.php
should be called. However, this never happens. For example when removing a timeline card I expect notify.php to be called, but it is not.
I really don't know how to dive deeper into this. Any idea someone?
-- edit --
Some more info on the issue (it was a long day yesterday..) ;)
The subscription is being set, when printing the subscription I see that the redirect url is correct:
$subscriptions = $mirror_service->subscriptions->listSubscriptions();
echo '<pre>';
print_r($subscriptions);
echo '</pre>';
results in:
Google_SubscriptionsListResponse Object
(
[__itemsType:protected] => Google_Subscription
[__itemsDataType:protected] => array
[items] => Array
(
[0] => Google_Subscription Object
(
[callbackUrl] => https://url/to/notify.php
[collection] => timeline
[id] => timeline
[kind] => mirror#subscription
[__notificationType:protected] => Google_Notification
[__notificationDataType:protected] =>
[notification] =>
[operation] =>
[updated] => 2014-03-21T09:34:45.391Z
[userToken] => 108736261363015154260
[verifyToken] =>
)
)
[kind] => mirror#subscriptionsList
)
In order to check if notify.php
is called I'm creating a "log file" in a writable folder on the server:
<?php
// all the way on top of notify.php
$file = __DIR__ .'/db/log.txt';
function logfile($txt) {
global $file;
$str = is_file($file)? file_get_contents($file) : '';
file_put_contents($file, $str ."\n". $txt);
}
logfile('--- notify.php is being run ---');
//..
The logfile is written when I request https://url/to/notify.php
, but the file is not written when I expect the subscription callback to fire.
Also the url https://url/to/notify.php
has been added to the redirect URIs in the Google Developer Console, along with the oauth2callback.php
Ok I got it fixed.. Or actually, nothing was wrong..
I assumed that I would get notifications of newly created and deleted timeline items. Believe I read this somewhere. However, today a collegue walked in who actually owns a glass device (the only one in the company). When I started playing with the menu items (you can't use them in the quickstart webapp) I could reply to a card and: notify.php was actually called!
Too bad this isn't well documented in the quickstart app itself.. But I am happy now :)
You should check to make sure that the subscription is actually created and contains the callback URL that you expect it to be.
Take a look at mirror-client.php:subscribe_to_notifications()
and the "insertSubscriptions" case in index.php
to verify the URL of the subscription.
You may also wish to add this function (from https://developers.google.com/glass/v1/reference/subscriptions/list ) which will list your subscriptions. You can then use this to determine what URL is stored and verify that URL is a secure working one.
function printSubscriptions($service) {
try {
$subscriptions = $service->subscriptions->listSubscriptions();
foreach ($subscriptions->getItems() as $subscription) {
print 'Collection: ' . $subscription->getCollection();
print 'User token: ' . $subscription->getUserToken();
print 'Verify token: ' . $subscription->getVerifyToken();
print 'Callback URL: ' . $subscription->getCallbackUrl();
if ($subscription->getOperation()) {
print 'Operation:';
foreach ($subscription->getOperation() as $operation) {
print ' * ' . $operation;
}
print 'Operation: ALL';
}
}
} catch (Exception $e) {
print 'An error occurred: ' . $e->getMessage();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.