Search code examples
phpgoogle-glassgoogle-mirror-api

Where does the Share button in Google Glass send the data?


I'm just starting to explore the functionalities of Google Glass.

What I'm trying to do is a simple Glassware that receives a video from the user, when the default 'Share' function is used.

I have seen the Quickstart project guide and I managed to upload my video in the python demo project; I also managed to implement the example PHP project code in my server.

However, I still can't figure out what exactly is happening where i tap the "Share" button on my Glass: where is sent the data? To my Glassware, to the generic Mirror API, or somewhere else? I suppose the Share function is doing something similar to what is described in the media upload page, but it's not clear how.

The code of the demo project seems to update the timeline event when I upload a picture/video; but if I'm not wrong, this code is just updating an already existing item with the "I have received your data!" caption.

(I'll report here the relevant code from the Google's notify.php sample: )

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;
      }
    }

... 

Where and when is actually received the video? I need to know this in order to perform additional operations when I receive the data.


Solution

  • The shared picture or video is downloaded through the download_attachment function in mirror-client.php of the Quickstart PHP project.

    Here is the function:

     /**
     * Download an attachment's content.
     *
     * @param string item_id ID of the timeline item the attachment belongs to.
     * @param Google_Attachment $attachment Attachment's metadata.
     * @return string The attachment's content if successful, null otherwise.
     */
    function download_attachment($item_id, $attachment) {
      $request = new Google_HttpRequest($attachment->getContentUrl(), 'GET', null, null);
      $httpRequest = Google_Client::$io->authenticatedRequest($request);
      if ($httpRequest->getResponseHttpCode() == 200) {
        return $httpRequest->getResponseBody();
      } else {
        // An error occurred.
        return null;
      }
    }