Issue Summary:
I am using a PHP quickstart to export data to Google Sheets. After authorizing, providing the access token results in an ‘Invalid token format’ error. For example:
<?php
$sheetClient = new SheetsHandler();
$authData = '{"token":"ABC123", "lifetime":3600}';
$sheetClient->setToken(json_decode($authData, true));
?>
What could be misconfigured?
In my experience, this error typically arises from a mismatch between the structure of your token data and what the PHP client library expects. I discovered that sometimes the key ‘token’ is incorrectly used instead of ‘access_token’. In one project, modifying our JSON to use ‘access_token’ instead made the token format valid. It might also be necessary to separate the lifetime information or use the key ‘expires_in’ if that suits the API requirements. Reviewing the library’s documentation on token structure should help resolve this issue.