I use the ClientLogin method and cURL to enter the Google API. This works great, and I get a token for later use. Now I can request docs.google.com using
$curl = curl_init();
$headers = array(
"Authorization: GoogleLogin auth=" . $auth,
"GData-Version: 3.0",
);
curl_setopt($curl, CURLOPT_URL, "https://docs.google.com/feeds/default/private/full");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
curl_close($curl);
This works fine, and I get a list of all the documents available in my google docs account. But if I try the same request on spreadsheets.google.com with the URL obtained from the api documentation :
https:
I get error 401 saying that the used token is invalid. I use the same token and request in both cases. Do I need another google spreadsheet token?
Edit: This is how I request a token:
$clientlogin_url = "https://www.google.com/accounts/ClientLogin";
$clientlogin_post = array(
"accountType" => "HOSTED_OR_GOOGLE",
"Email" => "my email",
"Passwd" => "my password",
"service" => "writely",
"source" => "my application name"
);
$curl = curl_init($clientlogin_url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clientlogin_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
preg_match("/Auth=([a-z0-9_-]+)/i", $response, $matches);
$auth = $matches[1];
curl_close($curl);