我尝试将视频分享到我的应用。它收到了通知,但没有contentUrl加载视频。以下是通知中的附件字段:
attachments: [{contentType: 'video/mp4', 'id': 'ps:5870152408634447570'}]
isProcessingContent字段也不存在。它尝试了一段时间(也许正在处理视频),但这没有任何区别。
https://developers.google.com/glass/v1/reference/timeline/attachments
有没有办法访问视频文件?
答案 0 :(得分:3)
contentUrl
元数据中未提供附件TimelineItem
,您需要向mirror.timeline.attachments.get
端点发送授权请求以检索有关附件的更多信息:
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
获得附件的元数据后,请检查isProcessingContent
属性:需要将其设置为False
才能检索contentUrl
。
遗憾的是,没有针对属性更改值的推送通知,并且您的服务必须使用指数退避进行轮询以节省配额和资源。
从附件的元数据中,当contentUrl
可用时,您可以检索附件的内容,如下所示:
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