附件的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