이 코드는 작동합니다. 문서 종류 항목을 만듭니다. 변수의 내용 : body (용어 = 'http : //schemas.google.com/docs/2007#file'에 대한 용어 = 'http : //schemas.google.com/docs/2007#document') 만 변경합니다. . 요청을 보낸 후 서버가 응답 < 400 Bad Request>를 반환합니다. 매우 이상합니다. Google Data API의 소스 코드를 추적 해본 결과 해당 종류 (http://schemas.google.com/docs/2007#file)를 발견했습니다. 파일 종류 항목을 만들려면 코드를 어떻게 수정합니까? 감사.프로토콜을 기준으로 Google 문서에 파일 종류 항목을 만드는 방법은 무엇입니까?
HttpWebRequest call = null;
HttpWebResponse echo = null;
StreamWriter send = null;
StreamReader read = null;
string data = string.Empty;
string body = string.Empty;
body = "<?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.txt</title>
</entry>";
call = HttpWebRequest.Create("https://docs.google.com/feeds/default/private/full") as HttpWebRequest;
call.Method = "POST";
call.Headers.Add("GData-Version: 3.0");
call.Headers.Add("Authorization: Bearer " + Access_Token);
call.ContentType = "application/atom+xml";
call.ContentLength = Encoding.UTF8.GetBytes(body).Length;
call.Headers.Add("X-Upload-Content-Length: 0");
send = new StreamWriter(call.GetRequestStream());
send.Write(body);
send.Close();
send.Dispose();
echo = call.GetResponse() as HttpWebResponse;
if (echo.StatusCode == HttpStatusCode.Created)
{
read = new StreamReader(echo.GetResponseStream());
data = read.ReadToEnd();
MessageBox.Show("entry.xml:" + Enviroment.NewLine + data);
read.Close();
read.Dispose();
}
else
{
MessageBox.Show("entry not created. " + echo.StatusCode.ToString() + "(" + echo.StatusDescription + ")");
}
echo.Close();
그런 다음 나는 종류 항목을 파일을 만들고 싶어요. 코드를 수정했습니다.
body = "<?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#file'/>
<title>test.exe</title>
</entry>";
call = HttpWebRequest.Create("https://docs.google.com/feeds/default/private/full?convert=false") as HttpWebRequest;
call.Method = "POST";
call.Headers.Add("GData-Version: 3.0");
call.Headers.Add("Authorization: Bearer " + Access_Token);
call.ContentType = "application/atom+xml";
call.ContentLength = Encoding.UTF8.GetBytes(body).Length;
call.Headers.Add("X-Upload-Content-Length: 0");
send = new StreamWriter(call.GetRequestStream());
send.Write(body);
send.Close();
send.Dispose();
echo = call.GetResponse() as HttpWebResponse;
수익 400 잘못된 요청
body = "<?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.exe</title>
</entry>";
call = HttpWebRequest.Create("https://docs.google.com/feeds/default/private/full?convert=false") as HttpWebRequest;
call.Method = "POST";
call.Headers.Add("GData-Version: 3.0");
call.Headers.Add("Authorization: Bearer " + Access_Token);
call.ContentType = "application/atom+xml";
call.ContentLength = Encoding.UTF8.GetBytes(body).Length;
call.Headers.Add("X-Upload-Content-Length: 0");
send = new StreamWriter(call.GetRequestStream());
send.Write(body);
send.Close();
send.Dispose();
echo = call.GetResponse() as HttpWebResponse;
반환 당신이 무엇을해야 https://developers.google.com/google-apps/documents-list/#creating_or_uploading_files에서 워드 프로세서, 업로드 URL로 ?convert=false
를 추가한다 (403) 금지
http://schemas.google.com/docs/2007#file에 '? convert = false'를 추가했습니다. 여전히 400 개의 잘못된 요청을 반환합니다. http://schemas.google.com/docs/2007#document에 '? convert = false'를 추가합니다. 여전히 403 Forbidden이 반환됩니다. – user1446337
문서에있는 HTTP 요청과 함께 보내는 HTTP 요청을 캡처하십시오. 또한 .NET 클라이언트 라이브러리를 사용하지 않는 이유는 무엇입니까? –
나는 질문을하고 나에게 대답했다. (http://stackoverflow.com/questions/10962335/how-to-upload-update-file-by-filestream-and-resumableuploader-in-c-sharp)하지만 슬러그 항목 제목을 수정할 수 없습니다. 그래서, 나는 .net을 사용하여 스스로 gdoc 프로토콜을 구현했습니다. 이제 gdoc 프로토콜의 모든 문제를 해결하고 gdoc 프로토콜 참조에 'POST 명령에서 문서를 업데이트 할 때 PUT 명령을 변경해야합니다.'와 같은 오류가 발생합니다. – user1446337