2012-07-01 74 views
0

下面的請求失敗,我無法弄清楚爲什麼,有什麼見解?文檔列表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) 

回答

0

您可以使用簡單的上傳來創建一個空文件,只需將您的網址替換爲https://docs.google.com/feeds/default/private/full,然後取消註釋GData-Version標頭。

另一種選擇(推薦)是使用新的Google Drive API的files.insert方法。