2013-04-23 69 views
3

我试着将视频分享给我的应用。它得到了通知,但没有contentUrl来加载视频。以下是通知中的附件字段:contentUrl缺少视频附件

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

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

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

是否有访问的视频文件的方法吗?

+1

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

回答

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