gpt4 book ai didi

google-glass - 视频附件缺少 contentUrl

转载 作者:行者123 更新时间:2023-12-02 20:19:01 28 4
gpt4 key购买 nike

我尝试将视频分享到我的应用程序。它收到了通知,但没有 contentUrl 来加载视频。以下是通知中的附件字段:

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

isProcessingContent 字段也不存在。它尝试等待一段时间(也许视频正在处理中),但这没有什么区别。

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

有办法访问视频文件吗?

最佳答案

TimelineItem元数据中未提供附件的contentUrl,您需要向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

关于google-glass - 视频附件缺少 contentUrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16179680/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com