2013-04-23 68 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