Google api refresh_token null and how to refresh access token

The refresh_token is only returned on the first request. When you refresh the access token a second time it returns everything except the refresh_token and the file_put_contents removes the refresh_token when this happens the second time. Modifying the code as following will merge in the original access token with the new one (see: array_merge). This … Read more

Automatically refresh token using google drive api with php script

You don’t have to periodically ask for an access token. If you have a refresh_token, PHP client will automatically acquire a new access token for you. In order to retrieve an refresh_token, you need to set access_type to “offline” and ask for offline access permissions: $drive->setAccessType(‘offline’); Once you get a code, $_GET[‘code’]= ‘X/XXX’; $drive->authenticate(); // … Read more

Google API Client “refresh token must be passed in or set as part of setAccessToken”

I got the same problem recently and i solved it with this. <?php $client->setRedirectUri($this->_redirectURI); $client->setAccessType(‘offline’); $client->setApprovalPrompt(‘force’); I explain ….. Refresh token is not returned because we didnt force the approvalPrompt. The offline mode is not enought. We must force the approvalPrompt. Also the redirectURI must be set before these two options. It worked for me. … Read more

How to get step count from Google Fit REST API like Google Fit app?

Which datasource the Google Fit app use to calculate step count? Google Fit App uses the estimated_steps data source to calculate step counts. DataSourceId: derived:com.google.step_count.delta:com.google.android.gms:estimated_steps Why there are different between datasources’s value and Google Fit value? Each data source represents a different device/source. I see you have a Sony Smart Watch and a HTC Desire … Read more

Google Calendar API v3 – authenticate with hardcoded credentials

I have found a solution that I think that is “the official” for what you want to do. First, you have to activate a Google API “Client ID for installed applications”. Go to the Google API console and create the project. Then, activate the calendar. Go to the “API access” option, and use the “Create … Read more

Token must be a short-lived token and in a reasonable timeframe

I stumbled upon the same issue at roughly the same time, so I expected a generic bug of Google but here is what had happened on my computer : raise HttpAccessTokenRefreshError(error_msg, status=resp.status) oauth2client.client.HttpAccessTokenRefreshError: invalid_grant: Invalid JWT: Token must be a short-lived token and in a reasonable timeframe was caused in my case by a poor … Read more

Google Drive PHP API – Simple File Upload

Use this code to authenticate and upload a test file. You need to set <YOUR_REGISTERED_REDIRECT_URI> (and also in console) to this document itself to authenticate. require_once ‘Google/Client.php’; require_once ‘Google/Service/Drive.php’; $client = new Google_Client(); // Get your credentials from the console $client->setClientId(‘<YOUR_CLIENT_ID>’); $client->setClientSecret(‘<YOUR_CLIENT_SECRET>’); $client->setRedirectUri(‘<YOUR_REGISTERED_REDIRECT_URI>’); $client->setScopes(array(‘https://www.googleapis.com/auth/drive.file’)); session_start(); if (isset($_GET[‘code’]) || (isset($_SESSION[‘access_token’]) && $_SESSION[‘access_token’])) { if (isset($_GET[‘code’])) { … Read more