Tuesday, November 17, 2009

Google API Going Crazy

Inserting a new row in a spreadsheet with Google API as been one of the greteast achievements of my entire life!

PowerShel WAY ;-)

STEPS:
1) WEBCLIENT request, with credentials, for https login page, receive "Auth"
2) convert received data to string
3) regex string, retrive all content after "Auth="
4) HTTP POST or other requests for CRUD options, send Auth in header with name "Authorization" and value "GoogleLogin auth=$auth"
5) call getstream and write data to buffer and flush

POST Headers:
# auth is retrived from previous https request with valid credentials
# for full code, contact me
$httpreq.Headers.Add("Authorization","GoogleLogin auth=$auth")
$httpreq.Headers.Add("GData-Version","3.0")

[string]$myxml="
<entry xmlns='http://www.w3.org/2005/Atom'
<xmlns:gsx='http://schemas.google.com/spreadsheets/2006/extended'>
<gsx:column1>1</gsx:column1>
<gsx:column2>1</gsx:column2>
</entry>
"

* this is really a single string variable
** carriage returns are ok
*** string needs to be converted to byte array to send over http
   --> Byte[] $tosend=encoding.GetString($myxml)
**** ALL in lowercase
***** At least ONE column not empty

No comments:

Post a Comment