asimlqt / php-google-spreadsheet-client

A PHP library for accessing and manipulating Google Spreadsheets
Other
543 stars 154 forks source link

require permission for accessing spreadsheet #163

Open rahul3883 opened 8 years ago

rahul3883 commented 8 years ago

i have created spreadsheets using the following code and its not showing up in my google drive, when i tried to access the url of the spreadsheet, its showing "require permission" button from google.

$client = new Google_Client();
$client->setAuthConfig('My Project.json');
$client->setScopes(array("https://spreadsheets.google.com/feeds",
    "https://www.googleapis.com/auth/drive",
    "https://www.googleapis.com/auth/drive.file",
    "https://www.googleapis.com/auth/drive.appdata"));

$token = $client->fetchAccessTokenWithAssertion();

$driveService = new Google_Service_Drive($client);

$fileMetadata = new Google_Service_Drive_DriveFile(array(
  'name' => 'tweets123',
  'mimeType' => 'application/vnd.google-apps.spreadsheet'));
$file = $driveService->files->create($fileMetadata, array(
  'fields' => 'id'));

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

$serviceRequest = new DefaultServiceRequest($token["access_token"]);
ServiceRequestFactory::setInstance($serviceRequest);

$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();

$spreadsheetFeed = $spreadsheetService->getSpreadsheetFeed();
$spreadsheet = $spreadsheetFeed->getByTitle('tweets123');

$worksheet = $spreadsheet->addWorksheet('worksheet11', 50, 20);

$cellFeed = $worksheet->getCellFeed();

$cellFeed->editCell(1,1, "name");
$cellFeed->editCell(1,2, "age");

$listFeed = $worksheet->getListFeed();
$listFeed->insert(["name" => "Someone", "age" => 25]);
i have created spreadsheets using the following code

$client = new Google_Client();
$client->setAuthConfig('My Project.json');
$client->setScopes(array("https://spreadsheets.google.com/feeds",
    "https://www.googleapis.com/auth/drive",
    "https://www.googleapis.com/auth/drive.file",
    "https://www.googleapis.com/auth/drive.appdata"));

$token = $client->fetchAccessTokenWithAssertion();

$driveService = new Google_Service_Drive($client);

$fileMetadata = new Google_Service_Drive_DriveFile(array(
  'name' => 'tweets123',
  'mimeType' => 'application/vnd.google-apps.spreadsheet'));
$file = $driveService->files->create($fileMetadata, array(
  'fields' => 'id'));

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

$serviceRequest = new DefaultServiceRequest($token["access_token"]);
ServiceRequestFactory::setInstance($serviceRequest);

$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();

$spreadsheetFeed = $spreadsheetService->getSpreadsheetFeed();
$spreadsheet = $spreadsheetFeed->getByTitle('tweets123');

$worksheet = $spreadsheet->addWorksheet('worksheet11', 50, 20);

$cellFeed = $worksheet->getCellFeed();

$cellFeed->editCell(1,1, "name");
$cellFeed->editCell(1,2, "age");

$listFeed = $worksheet->getListFeed();
$listFeed->insert(["name" => "Someone", "age" => 25]);

spreadsheet object :

Google\Spreadsheet\Spreadsheet Object ( [xml:protected] => SimpleXMLElement Object ( [id] => https://spreadsheets.google.com/feeds/spreadsheets/private/full/10VxwZhXzePj8JNKEDN7rkpAuaeOsp8VOqRi8cZ7VdhY [updated] => 2016-09-18T14:29:37.100Z [category] => SimpleXMLElement Object ( [@attributes] => Array ( [scheme] => http://schemas.google.com/spreadsheets/2006 [term] => http://schemas.google.com/spreadsheets/2006#spreadsheet ) ) [title] => tweets123 [content] => tweets123 [link] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [rel] => http://schemas.google.com/spreadsheets/2006#worksheetsfeed [type] => application/atom+xml [href] => https://spreadsheets.google.com/feeds/worksheets/10VxwZhXzePj8JNKEDN7rkpAuaeOsp8VOqRi8cZ7VdhY/private/full ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [rel] => alternate [type] => text/html [href] => https://docs.google.com/spreadsheets/d/10VxwZhXzePj8JNKEDN7rkpAuaeOsp8VOqRi8cZ7VdhY/edit ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [rel] => self [type] => application/atom+xml [href] => https://spreadsheets.google.com/feeds/spreadsheets/private/full/10VxwZhXzePj8JNKEDN7rkpAuaeOsp8VOqRi8cZ7VdhY ) ) ) [author] => SimpleXMLElement Object (my details)