3

I tried sharing a video to my app. It got the notification, but there is no contentUrl to load the video. Here is the attachments field in the notification:

attachments: [{contentType: 'video/mp4', 'id': 'ps:5870152408634447570'}]

The isProcessingContent field is not present either. It tried waiting a while (perhaps the video is being processed anyway), but that made no difference.

https://developers.google.com/glass/v1/reference/timeline/attachments

Is there a way to access the video file?

Alain
  • 6,044
  • 21
  • 27
avh
  • 101
  • 3
  • 1
    Have you tried accessing the attachment directly (attachments.get) with the ID to see if the contentUrl is included in the response there? https://developers.google.com/glass/v1/reference/timeline/attachments/get – Scarygami Apr 23 '13 at 21:52

1 Answers1

3

Attachment's contentUrl are not provided in the TimelineItem metadata, you need to send an authorized request to the mirror.timeline.attachments.get endpoint to retrieve more information about the attachment:

from apiclient import errors
# ...

def print_attachment_metadata(service, item_id, attachment_id):
  """Print an attachment's metadata

  Args:
    service: Authorized Mirror service.
    item_id: ID of the timeline item the attachment belongs to.
    attachment_id: ID of the attachment to print metadata for.
  """
  try:
    attachment = service.timeline().attachments().get(
        itemId=item_id, attachmentId=attachment_id).execute()
    print 'Attachment content type: %s' % attachment['contentType']
    print 'Attachment content URL: %s' % attachment['contentUrl']
  except errors.HttpError, error:
    print 'An error occurred: %s' % error

Once you get the attachment's metadata, check for the isProcessingContent property: it needs to be set to False in order to retrieve a contentUrl. Unfortunately, there are no push notifications for when the property changes value and your service would have to poll using exponential backoff in order to save quota and resources.

From the attachment's metadata, when the contentUrl is available, you can retrieve the attachment's content like this:

def download_attachment(service, attachment):
  """Download an attachment's content

  Args:
    service: Authorized Mirror service.
    attachment: Attachment's metadata.
  Returns:
    Attachment's content if successful, None otherwise.
  """
  resp, content = service._http.request(attachment['contentUrl'])
  if resp.status == 200:
    return content
  else:
    print 'An error occurred: %s' % resp
    return None
Alain
  • 6,044
  • 21
  • 27