1

문서 및 폴더를 만들고 삭제하는 데 필요한 거의 완전한 API를 얻었습니다. 하지만 문서를 업데이트하는 데 실패합니다. gdata를 사용할 때는 매우 쉽지만이 코드는 모든 안드로이드 장치에서 작동해야하므로 google api java 클라이언트를 사용해야합니다. 무엇 발생하는 난 그냥 (새 문서가 완벽하게 작동 만들기, 주어진 내용으로) 새 문서를 만들 것입니다google api java 클라이언트로 Google 문서 도구 업데이트하기

public void updateTest() throws IOException { 
    InputStreamContent isContent = new InputStreamContent(); 
    isContent.inputStream = new ByteArrayInputStream("NEW CONTENT".getBytes("UTF-8")); 
    isContent.type = "text/plain"; 

    HttpRequest request = transport.buildPostRequest(); 
    request.setUrl("https://docs.google.com/feeds/default/media/document:0A[snip]3Y"); 

    request.content = isContent; 

    // request.headers.set("If-Match", "*"); 

    try { 
     request.execute().parseAs(DocumentListEntry.class); 
    } catch (HttpResponseException e) { 
     if (Constant.DEBUG) Log.d(TAG, "error: " + e.response.parseAsString()); 
     throw e; 
    } catch (ClientProtocolException e) { 
     if (Constant.DEBUG) Log.d(TAG, "error: " + e.getMessage()); 
     throw e; 
    } 
} 

: 여기 업데이트를 테스트하는 방법입니다. 내가 추가 할 경우 "경우-경기 : *"- :

11-19 11:17:16.536: DEBUG/DocsAPI(32195): error: <errors xmlns='http://schemas.google.com/g/2005'> 
11-19 11:17:16.536: DEBUG/DocsAPI(32195): <error> 
11-19 11:17:16.536: DEBUG/DocsAPI(32195): <domain>GData</domain> 
11-19 11:17:16.536: DEBUG/DocsAPI(32195): <code>noPostConcurrency</code> 
11-19 11:17:16.536: DEBUG/DocsAPI(32195): <internalReason>POST method does not support concurrency</internalReason> 
11-19 11:17:16.536: DEBUG/DocsAPI(32195): </error> 
11-19 11:17:16.536: DEBUG/DocsAPI(32195): </errors> 
11-19 11:17:16.536: WARN/System.err(32195): com.google.api.client.http.HttpResponseException: 501 Not Implemented 
11-19 11:17:16.540: WARN/System.err(32195):  at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:209) 
... 

답변

3

당신이 명령을 PUT 사용해야하는 기존 문서를 업데이트 : 헤더,이 예외가 Updating documents

+2

당신은 나를 약 8 % 더 행복했다, 감사합니다! – pgsandstrom

+0

아, 10 %를 목표로 삼았습니다. Bummer;) –

+1

당신은 나를 3 % 더 행복하게 만들었습니다. 그래서 당신이 지금 당신의 목표를 초과했다고 생각합니다. ;) –

1

당신에게 쿼리 먼저 필요 파일. 응답에서 이름이 "edit-media"인 링크 목록 중에서 요소를 찾습니다. 그런 다음 해당 주소로 게시합니다.

아래 구글 - 클라이언트 API의 웹 사이트에서 구글의 샘플 프로젝트 문서-V3-원자의 OAuth 샘플에 추가 할 수있는 코드는 http://code.google.com/p/google-api-java-client/wiki/GoogleAPIs

private String queryRegistryforEditId() { 
    String str ="https://docs.google.com/feeds/default/private/full?title=" + URL_FRIENDLY_QUERY_PHRASE; 
    DocsUrl url = new DocsUrl(str); 

    DocumentListFeed feed; 
    try { 
     feed = DocumentListFeed.executeGet(transport, url); 
    } catch (IOException e) { 
     e.printStackTrace(); 
     return null; 
    } 

    //display(feed); 
    String ans = null; 
    //LIST OF FILES MATCHING QUERY 
    for (DocumentListEntry doc : feed.docs) { 
     //doc.content.src has url to download file 
     //I added src to content class that comes from the sameple code 
     Map<String, String> data = retriveDocUsingId(doc.content.src); 

     List<Link> lik = doc.links; 
     for (Link i : lik) { 
      //look for "edit-media" to get url to post edits to file 
      if (i.rel.equals("edit-media")) { 
       ans = i.href; 
       System.out.println(i.href); 
      } 
     } 
     //System.out.println(" doc.title: " + doc.title + " doc.id " + doc.id); 
    } 
    return ans; 
} 

private void updateDocumentText(String edit) { 
    HttpRequest request = transport.buildPutRequest(); 
    request.url = new GoogleUrl(edit); 

    GoogleHeaders headers = (GoogleHeaders)transport.defaultHeaders; 
    headers.contentType = "text/plain"; 
    headers.gdataVersion = "3"; 
    headers.slug = "examplefile"; 
    headers.ifMatch = "*";  
    request.headers = headers; 

    AtomParser parser = new AtomParser(); 
    parser.namespaceDictionary = Namespace.DICTIONARY; 
    transport.addParser(parser); 
    File file = new File ("/newfilepath/test233.txt"); 

    InputStreamContent bContent = new InputStreamContent(); 
    bContent.type = "text/plain"; 
    request.content = bContent; 

    try { 
     bContent.setFileInput(file); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } 

    com.google.api.client.http.HttpResponse res2; 
    try { 
     res2 = request.execute(); 
     System.out.println(res2.parseAsString()); 
    } catch (HttpResponseException e) { 
     try { 
      System.out.println(e.response.parseAsString()); 
     } catch (IOException e1) { 
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
     } 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 
관련 문제