Search code examples
zend-frameworkgdata-apigdatagoogle-sheets

using Zend_Gdata_Spreadsheets for public spreadsheets?


I have this code which is working, to load a Google Spreadsheet and load some data from it. If the spreadsheet in question is public, how do i modify the code to not require a username/password?

$key="keytothespreadsheet";
$user="[email protected]";
$pass="*****";

$authService = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$httpClient = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $authService);
$gdClient = new Zend_Gdata_Spreadsheets($httpClient);
$query = new Zend_Gdata_Spreadsheets_DocumentQuery();
$query->setSpreadsheetKey($key);
$feed = $gdClient->getWorksheetFeed($query);
print_r($feed);

Solution

  • In the following line, the HTTP client is optional:

    $gdClient = new Zend_Gdata_Spreadsheets($httpClient);
    


    So, just don't pass it. The following are equivalent:

    $gdClient = new Zend_Gdata_Spreadsheets();
    // or
    $gdClient = new Zend_Gdata_Spreadsheets(null);
    // or
    $gdClient = new Zend_Gdata_Spreadsheets(new Zend_Http_Client());