asimlqt / php-google-spreadsheet-client

A PHP library for accessing and manipulating Google Spreadsheets
Other
544 stars 152 forks source link

Cache Access Token? #121

Closed GustavoA23 closed 8 years ago

GustavoA23 commented 8 years ago

Is there a way to extend the duration of the access token either by using an offline cached token? or refreshing?

$client = new Google_Client();

putenv("GOOGLE_APPLICATION_CREDENTIALS=xxxxxxxxxxxxxxxxxxxxxx");
$client->useApplicationDefaultCredentials();

$client->setApplicationName("xxxxxxxxx");
$client->setScopes(['https://www.googleapis.com/auth/drive','https://spreadsheets.google.com/feeds']);

if ($client->isAccessTokenExpired()) {
    $client->refreshTokenWithAssertion();
        }

$tokenArray=$client->fetchAccessTokenWithAssertion();
$accessToken=$tokenArray["access_token"];

$serviceRequest = new Google\Spreadsheet\DefaultServiceRequest($accessToken);
Google\Spreadsheet\ServiceRequestFactory::setInstance($serviceRequest);
$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();

I initialize the service above , the problem is im working with a spreadsheet an iterating through rows (I have around 6k rows) and doing things with the data. After around close to 2k rows being iterated, I believe the access token expires, and it stops. How much of the above do I have to reinstate when I refresh the token? Im utilizing this

foreach ($listFeed->getEntries() as $entry){ 
}

to loop through the rows, is it possible to refresh the token while inside this loop and continue?

asimlqt commented 8 years ago

Hi, I'm not sure what the issue is.

Are you fetching data from a Google Spreadsheet which has ~6k rows and you're doing some processing for each entry? I can't see why it would take more then an hour to process only 6000 rows, what are you doing?

How about just writing the data to a csv file locally and then doing your processing on that?