Пример #1
0
function bootstrap_new_user()
{
    global $base_url;
    $client = get_google_api_client();
    $client->setAccessToken(get_credentials($_SESSION['userid']));
    // A glass service for interacting with the Mirror API
    $mirror_service = new Google_MirrorService($client);
    $timeline_item = new Google_TimelineItem();
    $timeline_item->setText("Welcome to the Mirror API PHP Quick Start");
    insert_timeline_item($mirror_service, $timeline_item, null, null);
    insert_contact($mirror_service, "php-quick-start", "PHP Quick Start", $base_url . "/static/images/chipotle-tube-640x360.jpg");
    subscribe_to_notifications($mirror_service, "timeline", $_SESSION['userid'], $base_url . "/notify.php");
}
Пример #2
0
     $new_timeline_item->setMenuItems($menu_items);
     insert_timeline_item($mirror_service, $new_timeline_item, null, null);
     $message = "Inserted a timeline item you can reply to";
     break;
 case 'insertTimelineAllUsers':
     $credentials = list_credentials();
     if (count($credentials) > 10) {
         $message = "Found " . count($credentials) . " users. Aborting to save your quota.";
     } else {
         foreach ($credentials as $credential) {
             $user_specific_client = get_google_api_client();
             $user_specific_client->setAccessToken($credential['credentials']);
             $new_timeline_item = new Google_TimelineItem();
             $new_timeline_item->setText("Did you know cats have 167 bones in their tails? Mee-wow!");
             $user_specific_mirror_service = new Google_MirrorService($user_specific_client);
             insert_timeline_item($user_specific_mirror_service, $new_timeline_item, null, null);
         }
         $message = "Sent a cat fact to " . count($credentials) . " users.";
     }
     break;
 case 'insertSubscription':
     $message = subscribe_to_notifications($mirror_service, $_POST['subscriptionId'], $_SESSION['userid'], $base_url . "/notify.php");
     break;
 case 'deleteSubscription':
     $message = $mirror_service->subscriptions->delete($_POST['subscriptionId']);
     break;
 case 'insertContact':
     insert_contact($mirror_service, $_POST['id'], $_POST['name'], $base_url . "/static/images/chipotle-tube-640x360.jpg");
     $message = "Contact inserted. Enable it on MyGlass.";
     break;
 case 'deleteContact':
Пример #3
0
// A glass service for interacting with the Mirror API
$mirror_service = new Google_MirrorService($client);
switch ($request['collection']) {
    case 'timeline':
        // Verify that it's a share
        foreach ($request['userActions'] as $i => $user_action) {
            if ($user_action['type'] == 'SHARE') {
                $timeline_item_id = $request['itemId'];
                $timeline_item = $mirror_service->timeline->get($timeline_item_id);
                // Patch the item. Notice that since we retrieved the entire item above
                // in order to access the caption, we could have just changed the text
                // in place and used the update method, but we wanted to illustrate the
                // patch method here.
                $patch = new Google_TimelineItem();
                $patch->setText("PHP Quick Start got your photo! " . $timeline_item->getText());
                $mirror_service->timeline->patch($timeline_item_id, $patch);
                break;
            }
        }
        break;
    case 'locations':
        $location_id = $request['itemId'];
        $location = $mirror_service->locations->get($location_id);
        // Insert a new timeline card, with a copy of that photo attached
        $loc_timeline_item = new Google_TimelineItem();
        $loc_timeline_item->setText("PHP Quick Start says you are now at " . $location->getLatitude() . " by " . $location->getLongitude());
        insert_timeline_item($mirror_service, $loc_timeline_item, null, null);
        break;
    default:
        error_log("I don't know how to process this notification: {$request}");
}