繁体   English   中英

使用Google Drive API将PDF转换为任何PDF格式

[英]Convert PDF to any with Google Drive API

我正在尝试将PDF转换为任何允许的格式,但在上传pdf文件后,响应不会对exportLinks进行内容处理。

我已经尝试了很多方法来管理获取exportLinks。 可以上载其他文档格式并成功导出。 我使用了来自developers.google.com的代码。

media_body = MediaFileUpload(filename, mimetype=mime_type, resumable=False)
body = {'title': title,
        'description': description,
        'mimeType': mime_type,
        }
# Set the parent folder.
if parent_id:
    body['parents'] = [{'id': parent_id}]

try:
    request = service.files().insert(body=body, media_body=media_body)
    #request.uri = "%s&convert=true&ocr=true" % request.uri
    #request.uri = "%s&convert=true" % request.uri
    request.uri = "https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart&alt=json&convert=true"
    logger.debug("Request: %s", request.uri)
    file_obj = request.execute()
    # Uncomment the following line to print the File ID
    # print 'File ID: %s' % file_obj['id']
    import json
    logger.debug('Get file result: %s' % json.dumps(file_obj, indent=4))
    return file_obj

...
export_links = source_file.get('exportLinks')
if not export_links:
    logger.debug('Warning: exportLinks does not exist')

为什么PDF上传的响应中没有exportLinks?

请Google团队同意,可以通过Drive API上传和导出PDF。

谢谢

[UPD]这是Httplib2的请求转储。 正如我所见,根据手册正确设置了查询。

Request: https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart&alt=json&convert=true
send: 'POST /upload/drive/v2/files?uploadType=multipart&alt=json&convert=true HTTP/1.1\r\n
Host: www.googleapis.com\r\n
content-length: 4425\r\n
accept-encoding: gzip, deflate\r\n
accept: application/json\r\n
user-agent: google-api-python-client/1.0\r\n
content-type: multipart/related; boundary="===============0758269123680398078=="\r\n
authorization: Bearer ya29.AHES6ZRDT0AJX8a5JN_u_0epF6ZCMGcqwyru1wzj22oVlMO9CfmFzlo\r\n
\r\n
--===============0758269123680398078==\nContent-Type: application/json\nMIME-Version: 1.0\n\n{"mimeType": "application/pdf", "description": "", "title": "Short_pdf.pdf"}\n--===============

这是在响应downloadLink:“downloadUrl”:“ https://doc-0c-2c-docs.googleusercontent.com/docs/securesc/2sgoib42bclb5coaj85g5574fd2b65bn/2lnqk989jdaepp4b8igdco1j8fu7m9l3/1373040000000/00639208221381605991/00639208221381605991/0By108D1dgCDkX0NFOXV0V2pNd2s?h=16653014193614665626&e=download&gd =真 “,”

遗憾的是,Google云端硬盘不通过Google云端硬盘API提供PDF文件的转换功能。

只有Google原生文档(Google文档/表格/幻灯片/图纸)具有exportLinks允许以多种导出格式下载Google文档。 所有其他文件 - 基本上常规文件,如PDF,图像等... - 有一个downloadUrl ,它允许您以原始格式下载文件本身。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM