附件的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
您是否尝试过直接与ID访问附件(attachments.get),看看是否的contentURL是否包括在那里的回应? https://developers.google.com/glass/v1/reference/timeline/attachments/get – Scarygami 2013-04-23 21:52:13