I embarked on this project thinking it would be simple. Many hours later I'm realizing the Google API is a bit of a labyrinth with multiple APIs and libraries. I really need please clear directions on how to go about doing this.
I created several Google Doc spreadsheets which I granted permission to other users to edit.
All I need is to programatically retrieve the info from these spreadsheets using PHP. However, I can't figure out how to connect to even start the retrieval.
Here is what I did so far:
1 - Installed the Google PHP API libraries.
2 - Created a Google API project in the same account. I have no idea which API I need and which oAuth keys I need.
3 - Installed the Google API Spreadsheet client from https://github.com/asimlqt/php-google-spreadsheet-client.
Well, now what? How do I send the API command to retrieve the spreadsheet I want. I'm unsure how to authenticate and how to retrieve. So far, I tried the below using the API Server Key for Google Drive....this was just a guess. I copied and pasted the below from the example in the Google API Spreadsheet client:
<?php
require_once 'php-google-spreadsheet-client-mastersrcGoogleSpreadsheetAutoloader.php';
$accessToken = 'xxxxxxxxxxxxxxxxxxxxxxx';
$request = new GoogleSpreadsheetRequest($accessToken);
$serviceRequest = new GoogleSpreadsheetDefaultServiceRequest($request);
GoogleSpreadsheetServiceRequestFactory::setInstance($serviceRequest);
$spreadsheetService = new GoogleSpreadsheetSpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();
?>
I receive the following error:
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:phpphp-google-spreadsheet-client-mastersrcGoogleSpreadsheetSpreadsheetFeed.php:43 Stack trace: #0 C:phpphp-google-spreadsheet-client-mastersrcGoogleSpreadsheetSpreadsheetFeed.php(43): SimpleXMLElement->__construct('') #1 C:phpphp-google-spreadsheet-client-mastersrcGoogleSpreadsheetSpreadsheetService.php(39): GoogleSpreadsheetSpreadsheetFeed->__construct(false) #2 C:phpgoogle_docd.php(11): GoogleSpreadsheetSpreadsheetService->getSpreadsheets() #3 {main} thrown in C:phpphp-google-spreadsheet-client-mastersrcGoogleSpreadsheetSpreadsheetFeed.php on line 43
Please, please. Clear instructions. I'm a complete Google API newbie. thanks. Examples on how to test in SOAPUI or via bash would also be helpful as I can then use that to figure out how to issue Curl request. Many thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…