English 中文(简体)
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="test@example.com";
$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);
最佳回答

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());
问题回答

Like @Matt, I wanted to access a public spreadsheet without supplying credentials. Thanks to @Derek Illchuk, I got part of the way there. It still wasn t working, however, until I learned the following:

  1. Note that the File > Publish to the Web feature is not the same thing as Sharing Settings > Public On The Web. If you forget to enable "Publish to the Web", you ll get this error: "Expected response code 200, got 400 The spreadsheet at this URL could not be found. Make sure that you have the right URL and that the owner of the spreadsheet hasn t deleted it."

  2. In the "Publish to the Web" settings, be sure to uncheck "Require viewers to sign in with their ___ account.". Otherwise you ll get this error: "Expected response code 200, got 403 You do not have view access to the spreadsheet. Make sure you are properly authenticated."

  3. According to Google s documentation, "The spreadsheets feed only supports the private visibility and the full projection." However, I found that I needed to specify public visibility and basic projection. Otherwise I got this error: "Expected response code 200, got 501 Bad or unsupported projection for this type of operation."

Here is what worked for me:

    $spreadsheetService = new Zend_Gdata_Spreadsheets(null);
    $query = new Zend_Gdata_Spreadsheets_CellQuery();
    $query->setSpreadsheetKey($spreadsheetKey);
    $query->setWorksheetId($worksheetId);
    $query->setVisibility( public ); //options are  private  or  public 
    $query->setProjection( basic ); //options are  full  or  basic 
    $cellFeed = $spreadsheetService->getCellFeed($query);

    foreach ($cellFeed as $cellEntry) {
        $text = $cellEntry->content->text;
        //Do something
        break; //I only wanted the first cell (R1C1).
    }




相关问题
Zend 邮件问题,涉及外国char子+ com子

泽斯德邮局在名称被定为具有外国性质(如“保”)和 com(”)的物品时,就放弃了一种例外(因为邮局(邮局)退回假)。 重新提出以下守则。

PHP Framework: Ebay Like Site

I am going to be builiding a site like ebay - with all the features of ebay. Please note my payment method is limited to paypal. What would be the best PHP framework to use to build this quickly, ...

Link to a specific step in onepage checkout

Is it possible to redirect the browser to nth step in the onepage checkout? If so, how would one go about doing it? I m working on a payment module and have a sort of "cancel" action that i would ...

Tagging with Zend Framework

I m trying to create the same solutions as below, but using a simple MySQL query (instead of the static version used below where the words/tags are implemented in the code). The name of the MySQL ...

dynamicaly adding textboxes to zend_form

I hope that this is a quick question to answer. I am developing a form using Zend_Form, I have a number of Zend_Dojo_Form_Element_Textboxs to add to this form dynamically. These are added from rows ...

热门标签