文档列表API创建失败

问题描述:

下面的请求失败,我无法弄清楚为什么,有什么见解?文档列表API创建失败

var atom = ["<?xml version='1.0' encoding='UTF-8'?>", 
      '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:docs="http://schemas.google.com/docs/2007">', 
      '<category scheme="http://schemas.google.com/g/2005#kind"', 
      ' term="http://schemas.google.com/docs/2007#document"/>', 
      '<title>', titleDoc, '</title>', 
      '</entry>'].join(''); 


xhr.open('POST', URI , true); 
xhr.setRequestHeader('Content-type', 'application/atom+xml'); 
//xhr.setRequestHeader('GData-Version', '3.0');                      
xhr.setRequestHeader('X-Upload-Content-Length', '0'); 
xhr.setRequestHeader('Authorization', 'OAuth ' + google.getAccessToken()); 
xhr.send(atom); 

这是从服务器

Request URL:https://docs.google.com/feeds/upload/create-session/default/private/full 
Request Method:POST 
Status Code:400 Bad Request 
Request Payload 
<?xml version='1.0' encoding='UTF-8'?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:docs="http://schemas.google.com/docs/2007"><category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/docs/2007#document"/><title>test</title></entry> 
Response Headersview source 
cache-control:no-cache, no-store, must-revalidate 
content-length:19 
content-type:text/html; charset=UTF-8 
date:Sun, 01 Jul 2012 06:46:21 GMT 
expires:Fri, 01 Jan 1990 00:00:00 GMT 
pragma:no-cache 
server:HTTP Upload Server Built on Jun 14 2012 02:12:09 (1339665129) 
status:400 Bad Request 
version:HTTP/1.1 

与GDATA版休止未注释的请求/响应包,但仍不会产生在谷歌文档一个文档

HTTP/1.1 200 OK 
status: 200 OK 
version: HTTP/1.1 
cache-control: no-cache, no-store, must-revalidate 
content-length: 0 
content-type: text/html; charset=UTF-8 
date: Sun, 01 Jul 2012 21:02:16 GMT 
expires: Fri, 01 Jan 1990 00:00:00 GMT 
location: https://docs.google.com/feeds/upload/create-session/default/private/full?convert=false&upload_id=AEnB2UoaVeHUGhiIgKm9fL-WL_Fd1DdAAh7rdYDx6G6cseLwHgAMBfkdt42kf9YiKFJ8q9tiZ8vLVUb3Sr-KVUZi01m3vY6ZUw 
pragma: no-cache 
server: HTTP Upload Server Built on Jun 14 2012 02:12:09 (1339665129) 

您可以使用简单的上传来创建一个空文件,只需将您的网址替换为https://docs.google.com/feeds/default/private/full,然后取消注释GData-Version标头。

另一种选择(推荐)是使用新的Google Drive API的files.insert方法。