Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Access token is invalid' error in spreadsheet library php #176

Open
johnnash03 opened this issue Apr 6, 2017 · 0 comments
Open

'Access token is invalid' error in spreadsheet library php #176

johnnash03 opened this issue Apr 6, 2017 · 0 comments

Comments

@johnnash03
Copy link

I need to upload spreadsheet via google drive in cakephp.I am using google-api-php-client to generate access token and php-google-spreadsheet-client to access the sheets.Code is as follows:

`
function test() {
require_once '../vendors/google-api-php-client-2.1.1/vendor/autoload.php';
$client = new \Google_Client();
$client->setApplicationName("spreadsheet");
$client->setDeveloperKey("//My developerkey");
$client = new Google_Client();
$client->setAuthConfig('client_id.json');
if( !isset($_GET['code']) ) {

    $client->addScope(Google_Service_Drive::DRIVE);
    $client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/test' );
    $auth_url = $client->createAuthUrl();
    header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
} else {

    $client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/test' );
    $auth_url = $client->createAuthUrl();
    $token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
    $client->setAccessToken($token);

    $serviceRequest = new Google\Spreadsheet\DefaultServiceRequest($token['access_token']);
    Google\Spreadsheet\ServiceRequestFactory::setInstance($serviceRequest);
    $spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
    $spreadsheetFeed = $spreadsheetService->getSpreadsheetFeed();
    $spreadsheet = $spreadsheetFeed->getByTitle('Test');
}

`

But I get the error that access token is invalid as shown in following image:

gmdby

What is it that I am doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant