以下请求失败,我无法找出原因,任何见解?
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版本取消注释,但这仍然无法在Google文档中创建文档
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)
答案 0 :(得分:0)
您可以使用简单上传来创建空文件,只需将您的网址替换为https://docs.google.com/feeds/default/private/full
并取消注释GData-Version标头。
另一个选项(推荐)是使用新版Google Drive API的files.insert方法。