Have been struggling to connect to Google API
via PHP using Service Account. If to use examples provided by API (link) and google developers site itself (or any other source from google searches), I'm getting the error
{
"error": "invalid_grant",
"error_description": "Invalid JWT Signature."
}
And if to search how to connect using JWT as well, there are only JS or JAVA or PYTHON examples.
Any real experience out there how to correctly get the connection?
I have:
service account set up and allowed to use Search Console (and analytics)
set up the API to server
added service account address to Search Console for site we need the data from
downloaded and added the key file.
All goes well till I start making the actual request for data. Then the JWT error appears.
ANY input is appreciated!
Got solution by removing service account from google console and created new.
Related
I am working on an application to sync with google calendar, I got the following error:
Error refreshing the OAuth2 token,
message: '{
"error" : "unauthorized_client",
"error_description" : "Client is unauthorized to retrieve access tokens using this method."
}'
When you create a project on Google Developer console there are several types of clients you can create.
Browser clients are used for web applications, Native clients are used for installed applications, Service account clients are used for background applications mostly.
The authentication code used to use each type of client is different. You cant use the code for native applications with a web application or you will get the following error.
Client is unauthorized to retrieve access tokens using this method.
Solution figure out what type of application you are trying to make. Then make sure you created the corect client type on Google Developer console and are using the code designed for that client type.
I am developing a website where I am integrating Google Analytics in the project. All is working fine but sometimes I get the error that "Number of Requests Limit exceeded. Please signup to Google Developers console" something like that. I have searched the internet and they have described that obtain the "Client ID" from Google Developers Console.
I have done that but now I cannot find that where to put that "Client ID" in the API file? I am using the "gapi" class for fetching the Google Analytics data. But in the "gapi.class.php" file there is no option for the "Client ID" which I have obtained from Google Developers Console.
Where to put the "client ID" OR there is something I am doing wrong?
It seems that you are using this library which is a third party library that authenticate the user through email/password in order to access his analytics account.
If you need to access the GA API as documented here maybe you will have to use another library. Google is providing a PHP library to access the API. Also, if you look at the code samples you will see that they are using the API KEY and the Client ID to authenticate (the Client ID is not always needed depending on what you are requesting).
I am using the PHP version of the Google Glass Developer Kit. Setup everything per the sample code instructions. API/credentials are all fine, account billing is setup, have added the Mirror API to the project, but after I permission the application, I get the following Error:
An error ocurred: Error calling POST
https://www.googleapis.com/mirror/v1/timeline?key=xxxxxx
(403) Access Not Configured.
Please use Google Developers Console to activate the API for your project.
I have added the Mirror API and have Billing active and setup so have no idea why i am getting the error message. Testing the app via the Glass Explorer works just fine.
Google APIs have been known to misbehave when you provide both OAuth2 credentials and an API Key. Also since you have to use OAuth2 to access the Mirror API, the key=xxxxx isn't necessary anyway.
If you are using the Google APIs Client Library for PHP you can simply remove the following line from your code:
$client->setDeveloperKey($key);
Not entirely sure if this causes your issue, but I have come across similar issues in other Google APIs.
In Google API console for your project (https://code.google.com/apis/console/)
Make sure that your "Public API access" or "Key for server application" has allowed the IP address of your server.
Also make sure you have the proper "Redirect URIs", if you get refused, look at your php logs, I had this:
PHP Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling GET https://www.googleapis.com/mirror/v1/timeline?maxResults=3&key=: (403) Access Not Configured. Please use Google Developers Console to activate the API for your project.'
use your $base_url + /oauth2callback.php to find out what the correct Redirect URI is.
I managed to solve the issue by adding the IP address and REDIRECT URIs and it runs both on my local machine and on the server. (same code, same key)
PS: I want to thank Scarygami, disabling the $client->setDeveloperKey($key); helped me find the solution.
I am implemented In App Billing for android.I wanted to implement subscription validity checking through my backend server. As Google Play Documentation, for making call for Google Play API,need authentication using oauth 2.0.
I followed instructions for registering project and creating credentials. But from there I have no idea how to use those credentials, I tried authentication via CURL request, but it asking permission as shown in follwing image
This permissions works fine I can exchange code and get access token, but all this done by manually, how should I implement this on backend.
I even try to use google api php library provided by Google, but It adds confusion. Also they didn't provide any example, how to use library.
Can anybody elaborate how exactly use library or pure php?
Thanks in advance.
To perform LVL and/or IAB validation on a server, do not access Google servers directly from the server. Even if all information were available, you would face integrity problems, because your app and your server will see different information due to synchronization latencies.
Instead, use your app as a proxy and validate the Google Play information on your server as described here.
I am using Adwords API from last 3 months and all of a sudden today it is coming up with error message as follows:
Uncaught exception 'AuthTokenException' with message 'Failed to get authToken. Reason: BadAuthentication'
I am using google adwords V201101 php library with auth.ini containing all user details and settings.ini with https://adwords.google.com not sandbox environment. Can anyone help me with this please???
Thanks,
Murali.
you may requesting authToken from ClientLogin service too many times, that is way you get 'CaptchaRequired'.
Request authToken just for the first time, and then cache it for subsequent requests.
Check this out http://goo.gl/TOX6N
I recently had this problem trying to connect to Google DFP. I copied perfectly working code from my localhost after development and ran it on my remote cloud server. I then received the
Failed to get authToken
message. The reason was that google was blocking the attempted login as a security measure because it was a new location. I had to log into the google account (from the web) with those credentials in order to see the message and confirm the added login location. Everything worked fine after that authorization.
I've stumbled across this question and thought that this info may help someone else.
BadAuthentication means your username/password is incorrect. May be someone changed the account password, may be auth.ini got modified by mistake.
See detailed error codes here: http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html#Errors
Cheers,
Anash
I started getting this error after somebody in my organization updated the password for the account my app was using to log in. The best way to avoid this happening again is to use OAuth2.
It's as easy as going to the Google API console and creating a Client ID for Installed Applications (under API access) for your project. You then use the Client ID and Client Secret in your Adwords API auth.ini file.
Next you run the examples/AdWords/Auth/GetRefreshToken.php script which will have you grant your app access to your Adwords account. You'll end up with a Refresh Token which you need to add to your auth.ini.
The ClientLogin (username and password) method of authentication is being deprecated in favour of the above so best to migrate ASAP.