Question

I am using this library https://github.com/asimlqt/php-google-spreadsheet-client to interact with Google's spreadsheet api.

Using the examples provided pretty much as is, I have this wip code:

$request = new Google\Spreadsheet\Request($access['access_token']);
    $serviceRequest = new Google\Spreadsheet\DefaultServiceRequest($request);
    Google\Spreadsheet\ServiceRequestFactory::setInstance($serviceRequest);

    $spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
    $spreadsheetFeed = $spreadsheetService->getSpreadsheets();
    var_dump($spreadsheetFeed);

    $spreadsheet = $spreadsheetFeed->getByTitle('a spreadsheet');

    echo "<h1>Start spreadsheet single feed</h1>";
    var_dump($spreadsheet);

The final line is unexpectedly printing null. I was hoping someone familiar with the library could nudge me in the right direction.

BTW, this is what the $spreadsheetFeed dump reveals:

    object(Google\Spreadsheet\SpreadsheetFeed)#263 (2) { 
["xml":"Google\Spreadsheet\SpreadsheetFeed":private]=>
 object(SimpleXMLElement)#200 (5) { ["id"]=> string(63) 
"https://spreadsheets.google.com/feeds/spreadsheets/private/full" 
["updated"]=> string(24) "2014-04-22T15:41:32.296Z" 
["category"]=> object(SimpleXMLElement)#244 (1) {
 ["@attributes"]=> 
array(2) { 
["scheme"]=> string(43) "http://schemas.google.com/spreadsheets/2006" 
["term"]=> string(55) "http://schemas.google.com/spreadsheets/2006#spreadsheet" 
} 
} 
["title"]=> string(100) "Available Spreadsheets - <redacted!>" 
["link"]=> array(3) { 
[0]=> object(SimpleXMLElement)#243 (1) {
 ["@attributes"]=> array(3) {
 ["rel"]=> string(9) "alternate" 
["type"]=> string(9) "text/html" ["href"]=> string(22) "http://docs.google.com" 
} 
}
 [1]=> object(SimpleXMLElement)#245 (1) { 
["@attributes"]=> array(3) { 
["rel"]=> string(37) "http://schemas.google.com/g/2005#feed" 
["type"]=> string(20) "application/atom+xml" 
["href"]=> string(63) "https://spreadsheets.google.com/feeds/spreadsheets/private/full" 
} 
} 
[2]=> object(SimpleXMLElement)#246 (1) { 
["@attributes"]=> array(3) { 
["rel"]=> string(4) "self" 
["type"]=> string(20) "application/atom+xml" 
["href"]=> string(63) "https://spreadsheets.google.com/feeds/spreadsheets/private/full" 
} 
} 
} 
} 
["storage":"ArrayIterator":private]=> array(0) { 
} 
}

It appears to not contain any spreadsheets at all which is highly confusing as I'm confirming the presence of the desired spreadsheet successfully earlier in the code via the drive api. Obviously there is some sort of discrepancy between the two libraries I am using that isn't documented, but I have no idea to to debug it.

The drive library is the google inhouse one here https://github.com/google/google-api-php-client

Was it helpful?

Solution 2

Just to give some resolution (and maybe a pointer for someone else).

I came back to the problem fresh and discovered that there is an unspoken assumption in the google spreadsheet api that the file being accessed is a native google spreadsheet. Once I changed my file creation to create that instead of a .xls file everything resolved itself.

OTHER TIPS

I was not able to view existing sheets that should have shown up in spreadsheetFeed , i found and article by karl kranich on his web site stating that the document needs to be shared with the oath developer email address with edit permissions. After sharing it with edit permissions I see it in the list now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top