Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create a Folder with Google Drive REST AP and HTTPClient?
    primarykey
    data
    text
    <p>I am using Google Drive REST API with HTTPClient to create a folder. The REST API is document <a href="https://developers.google.com/drive/v2/reference/files/insert#try-it" rel="nofollow">here</a> Please note that the REST AP Request executes -- but uses the wrong data: tt creates a new file called "untitled" and puts my json there.</p> <p>I have tried different methods of building the POST request with HTTPClient which execute successfully -- but somehow the Google Drive responds with creating a file and returns this data and ignores POST data that I submit.</p> <p>This is what the server reponds with<br> ..</p> <p>"kind": "drive#file", "id": "0B-fYJN-c4UDjUlh1TUZadF9vejA", this is a valid ID "title": "Untitled", ----wrong title "mimeType": "application/json; charset=UTF-8", -- this is the wrong mimeType ..</p> <p>I have tried the following ways of invoking the API : I am not sure what is happening to the data I am sending with the post. </p> <p>1) Using form name value pairs</p> <pre><code>DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost("https://www.googleapis.com/upload/drive/v2/files?key="+GoogleClientConstants.GOOGLE_api_key); postRequest.addHeader("Authorization", "Bearer " + accessToken); postRequest.addHeader("Content-Type", "application/json; charset=UTF-8"); List &lt;NameValuePair&gt; nvps = new ArrayList &lt;NameValuePair&gt;(); nvps.add(new BasicNameValuePair("title", "vip")); nvps.add(new BasicNameValuePair("mimeType", "application/vnd.google-apps.folder")); postRequest.setEntity(new UrlEncodedFormEntity(nvps, org.apache.http.Consts.UTF_8 )); HttpResponse response = httpClient.execute(postRequest); </code></pre> <p>2) Using StringEntity</p> <pre><code>JSONObject jo= new JSONObject(); jo.element("title", "pets").element("mimeType", "application/vnd.google-apps.folder"); ContentType contentType= ContentType.create("application/json", Charset.forName("UTF-8")) ; StringEntity entity = new StringEntity(jo.toString(), contentType); logger.info(" sending "+ jo.toString()); postRequest.setEntity(entity); HttpResponse response = httpClient.execute(postRequest); </code></pre> <p>In both cases , Google API responds with 200 and the above mentioned returned FileResource. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload