Dev Dev - 8 days ago 7
PHP Question

unable to access google spreedsheets values using php

I'm installed
google api for OAuth2 php lib; here: https://code.google.com/p/google-api-php-client/
google spreadsheet api php lib; here: https://github.com/asimlqt/php-google-spreadsheet-client

created the credentials on the API Console using service account https://console.developers.google.com/

Here is the php script I used in combination with the above:

require_once('vendor/autoload.php');
require_once('vendor/composer/autoload_classmap.php');
require_once('vendor/composer/autoload_real.php');
require_once __DIR__.'/vendor/google/apiclient/src/Google/Auth/AssertionCredentials.php';

use Google\Spreadsheet\DefaultServiceRequest;
use Google\Spreadsheet\ServiceRequestFactory;
use Google\Spreadsheet\SpreadsheetService;

const G_CLIENT_ID = 'my_client_id';
const G_CLIENT_EMAIL = 'email address';
const G_CLIENT_KEY_PATH = 'key.p12';
const G_CLIENT_KEY_PW = 'notasecret';


$obj_client_auth = new Google_Client ();
$obj_client_auth -> setApplicationName ('newproject');
$obj_client_auth -> setClientId (G_CLIENT_ID);
$obj_client_auth -> setAssertionCredentials (new Google_Auth_AssertionCredentials (
G_CLIENT_EMAIL,
array('https://spreadsheets.google.com/feeds','https://docs.google.com/feeds'),
file_get_contents (G_CLIENT_KEY_PATH),
G_CLIENT_KEY_PW
));
$obj_client_auth -> getAuth () -> refreshTokenWithAssertion ();
$obj_token = json_decode ($obj_client_auth -> getAccessToken ());
$accessToken = $obj_token->access_token;
$serviceRequest = new DefaultServiceRequest($accessToken);
ServiceRequestFactory::setInstance($serviceRequest);
$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();
$spreadsheet = $spreadsheetFeed->getByTitle('NewSpreadSheet');
$worksheetFeed = $spreadsheet->getWorksheets();
$worksheet = $worksheetFeed->getByTitle('sssNew Worksheet');
$listFeed = $worksheet->getListFeed();
$row = array('name'=>'John', 'age'=>25);


I receive the following error:
Call to a member function getWorksheets() on a non-object...
I'm not getting how correct it...
Any help n suggestions

Dev Dev
Answer

I got it... the issue is about i didn't share my spreadsheet... when i shared my spreadsheet with client email then i'm able to insert records into the desired sheets... now i'm able to access every sheet,insert,delete everything...

So, when ever anyone got this problem just share your sheet with your client email.