I want to update my google spread sheet after my form submit with php
I have used library "google-api-php-client"
My code for that is below to authentication with OAuth2 authentication,
private function authenticate()
{
/*
* Authentication using the library 'google-api-php-client' which uses 'Oauth2'.
*/
require 'google-api-php-client/src/Google/autoload.php';
$scopes = array('https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive');
$pri_key = file_get_contents(realpath(dirname(__FILE__)).'/My Project service account.p12');
$credentials = new Google_Auth_AssertionCredentials(
'CLIENT_ID', #google dev console email
$scopes,
$pri_key
);
$this->client = new Google_Client();
$this->client->setAssertionCredentials($credentials);
if ($this->client->getAuth()->isAccessTokenExpired()) {
$this->client->getAuth()->refreshTokenWithAssertion();
}
$tokenData = json_decode($this->client->getAccessToken());
$this->accessToken = $tokenData->access_token;
}
Here I have create one service account and web application in my gmail account and from there above I have used client Id and p12 file, but it gives me below error,
Google_Auth_Exception
IT WAS THROWN IN
\google-api-php-client\src\Google\Auth\OAuth2.php on line 363
MESSAGE
Error refreshing the OAuth2 token, message: '{
"error" : "invalid_grant",
"error_description" : "Invalid JWT Signature."
}'
Is there any thing missing from me in this or follow wrong flow ???