Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Spreadsheet API update \ edit with protocol
    primarykey
    data
    text
    <p>I'm trying to implement some basic functionality for Google Spreadsheets, using the protocol specification with requests.</p> <p>The reason i'm doing this because it is for Android, and gdata-java library doesn't really work and the alpha android one doesn't really cut it. I managed to implement authentication, and get for lists, and delete, but for editing \ updating a row i can't really wrap my mind around it.</p> <p>For example i want to change the contents of a cell <a href="http://code.google.com/apis/spreadsheets/data/2.0/developers_guide_protocol.html#UpdatingCells" rel="nofollow noreferrer">here</a> is the specification for the protocol</p> <p>From my understanding of it, i have to send some sort of atom or xml formatted request to the edit URL. I never sent such type of requests.</p> <p>I also found <a href="http://www.devcomments.com/I-need-to-insert-update-delete-events-in-google-calendar-using-to112717.htm" rel="nofollow noreferrer">this</a>, which gives a clue on how it should be done (also an unanswered question on a forum), but didn't really managed it.</p> <p>Here is my authentication function if you need it, so you don't implement it again, if you want to try and code it.</p> <pre><code>/** * Logs in to the Google service using the ClientLogin HttpRequest API and returns an authentification token */ private String getAuthToken() { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(CLIENT_LOGIN_ADDRESS); List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(); nameValuePairs.add(new BasicNameValuePair("accountType", "GOOGLE")); nameValuePairs.add(new BasicNameValuePair("Email", "username@gmail.com")); nameValuePairs.add(new BasicNameValuePair("Passwd", "password")); nameValuePairs.add(new BasicNameValuePair("service", "wise")); nameValuePairs.add(new BasicNameValuePair("source", SERVICE_NAME)); try { httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } catch (UnsupportedEncodingException e) { //Log.e("ERROR", "UnsupportedEncodingException"); } //Log.v("TEST", "Executing request " + httppost.getURI()); ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler(); String responseBody = null; try { responseBody = httpclient.execute(httppost, responseHandler); } catch (ClientProtocolException e) { //Log.e("ERROR", "ClientProtocolException"); } catch (IOException e) { //Log.e("ERROR", "IOException"); } //Log.v("TEST", "response:" + responseBody); String[] vals = responseBody.split("\n")[2].split("="); String auth_string = vals[1]; //Log.v("TEST", "auth_token:" + vals[1]); return auth_string; } </code></pre> <p>Here is what i'm trying as the update function, note, edit URL's are for my document won't work if you try it, it's just for an iea on what i have so far : </p> <pre><code>/** * Ignore this i use it for testing */ public void justTesting() { String url = "http://spreadsheets.google.com/feeds/cells/tl7RKkCaAxvO1f3U9Y8k5Dw/od6/private/full/R2C1/1q0cdh"; HttpClient httpclient = new DefaultHttpClient(); HttpPut httpput = new HttpPut(url); httpput.addHeader(new BasicHeader("Authorization", "GoogleLogin auth=" + getAuthToken())); httpput.addHeader(new BasicHeader("GData-Version", "2.0")); HttpEntity he = null; String messageBody = "&lt;entry&gt;"+ "&lt;id&gt;https://spreadsheets.google.com/feeds/cells/tl7RKkCaAxvO1f3U9Y8k5Dw/od6/private/full/R2C1&lt;/id&gt;"+ "&lt;link rel=\"edit\" type=\"application/atom+xml\""+ " href=\"https://spreadsheets.google.com/feeds/cells/tl7RKkCaAxvO1f3U9Y8k5Dw/od6/private/full/R2C1\"/&gt;"+ "&lt;gs:cell row=\"2\" col=\"2\" inputValue=\"300\"/&gt;"+ "&lt;/entry&gt;"; try { he = new StringEntity(messageBody); } catch (UnsupportedEncodingException e) { //Log.e("ERROR", "UnsupportedEncodingException"); } httpput.setEntity(he); try { HttpResponse hr = httpclient.execute(httpput); //Log.d("DEBUG", "sl : " + hr.getStatusLine()); } catch (ClientProtocolException e) { //Log.e("ERROR", "ClientProtocolException"); } catch (IOException e) { //Log.e("ERROR", "IOException"); } //Log.v("TEST", "executed"); } </code></pre> <p>This currently gives a 400 Bad request. Also I'm trying to achieve this using Apache HttpClient. </p> <p>Does anyone have any idea on how this might be achieved \ implemented \ how what request i should send?</p> <p>Thanks, your help will be greatly appreciated.</p> <hr> <p>I made some progress and wrote this : </p> <pre><code>public void justTesting() { String url = "https://spreadsheets.google.com/feeds/cells/tl7RKkCaAxvO1f3U9Y8k5Dw/od6/private/full/R2C1"; HttpClient httpclient = new DefaultHttpClient(); HttpPut httpput = new HttpPut(url); httpput.addHeader(new BasicHeader("Authorization", "GoogleLogin auth=" + getAuthToken())); httpput.addHeader(new BasicHeader("GData-Version", "3.0")); HttpEntity he = null; String messageBody = "&lt;entry xmlns='http://www.w3.org/2005/Atom' xmlns:gs='http://schemas.google.com/spreadsheets/2006'&gt; &lt;id&gt;http://spreadsheets.google.com/feeds/cells/tl7RKkCaAxvO1f3U9Y8k5Dw/od6/private/full/R2C1 &lt;/id&gt; &lt;gs:cell row='2' col='1' inputValue='mouuuuuuuuusee'/&gt; &lt;/entry&gt;"; //RequestEntity requestEntity = new StringRequestEntity(xml.toString(), "application/atom+xml", "UTF-8"); try { he = new StringEntity(messageBody); } catch (UnsupportedEncodingException e) { Log.e("ERROR", "UnsupportedEncodingException"); } httpput.addHeader("Content-Type", "application/atom+xml"); httpput.setEntity(he); try { HttpResponse hr = httpclient.execute(httpput); Log.d("DEBUG", "sl : " + hr.getStatusLine()); } catch (ClientProtocolException e) { Log.e("ERROR", "ClientProtocolException"); } catch (IOException e) { Log.e("ERROR", "IOException"); } Log.v("TEST", "executed"); } </code></pre> <p>Now it gives me a 403 Forbidden. Any idea why?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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