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).
Related
I want to get statistics on sent messages. Found this method in the documentation, but the request was unsuccessful. Requires authentication.
My team uses the Firebase Admin SDK for PHP to send messages. I tried to find this method in the documentation, but did not find it.
Do have Firebase Admin SDK for the PHP method to get statistics, maybe I just missed it?
Or probably can I authorize with Firebase Admin SDK for PHP, and send GET https://fcmdata.googleapis.com/v1beta1/{parent=projects/*/androidApps/*}/deliveryData ?
It looks like the SDK you're using does not wrap the Google Analytics 4 Data API that you linked. There's nothing we can do here about it, so I recommend either filing a feature request on the repo of that SDK, or (even better) filing a pull request that adds the feature. :)
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.
I've currently got around 100 sites in Analytics across a few different Google Accounts and one single account has full permissions for every site. If possible I'd like to avoid having to manually add permissions for the Google Service account to each analytics profile.
I'm using the Google Analytics PHP Interface
When attempting to impersonate a user using the $delegate_email argument, I get the following exception:
GAPI: Failed to authenticate user. Error: "{
"error": "unauthorized_client",
"error_description": "Unauthorized client or scope in request."
}
I have read elsewhere about needing to 'Delegate domain-wide authority to the service account' using the Google Apps admin console. However we don't have Google Apps at all. Is there any way around this?
tl;dr
Is there a way to get read only access to Google analytics using a service account and impersonating a user without Google Apps?
I would first encourage you to go through the various Scenarios listed on Google OAuth 2.0 documentation and decide which is best for your application.
Service account require that you add a user to each account you wish to access, but with a web server application the end user simply authorizes your application to read their Google analytics data.
The scope you are looking for is:
https://www.googleapis.com/auth/analytics.readonly
I've been crawling the internet all morning trying to figure this out. I'm trying to get access to a Adwords test account through the API but I keep receiving "An error has occurred: { "error" : "invalid_grant" }". I've seen this is quite a common problem so perhaps if I outline what I've done step by step someone can correct me. Hopefully!
Created a Google adwords account and set up a campaign.
Created a MCC account. Added Google adwords account and applied for API access (pending). Noted API key, client id for auth.ini.
Created a test MCC account and added Google adwords account. Noted client id for auth.ini.
Using the Google account of both MCC accounts went into the API console and created a new installed application app. Noted all keys/tokens.
Downloaded the PHP code examples and libs. Ran get GetRefreshToken.php, granted accesses to app(s) and noted refresh token for auth.ini
Set up auth.ini populating developerToken, userAgent, clientCustomerId, client_id, client_secret and refresh_token.
Now I've tried using BOTH sets of tokens and ids from the test MCC account API console and the live MCC account API console. Both give me the same error. I've tried regenerating all tokens several times.
Gave up and came crawling to StackOverFlow.
Is the invalid_grant message related to Auth or my developerToken token not being activated yet (sure it said I could use my test account though) or because I haven't set up any of the billing?
In my case the problem was at step 5 in your list; I had copied the authorization code from my browser after granting access, rather than the refresh token generated by GetRefreshToken.php after I pasted the authorization code there.
I had the same situation for a long time.
But solution was very simple.
The code getting after authorizing the Google is not your refresh token.Its is only an access token(I guess.)
You have to add this code to GetAccessToken's $code variable function in getrefreshtoken.php file and it will return the actual Refresh token.
This solved my issue.
It is very important to note that the SDK is designed to be used through PHP-Cli. So please don't use it via browser. If you still run it by commenting out return line you'll get into further problems to comment that on each file :)
I try to make a validation of purchases on the server, but it can't to make a request to Google Play Android Developer API. After a request it shows this one:
Error calling GET https://www.googleapis.com/androidpublisher/v1.1/applications/my.app.id/inapp/my_in_app_purchase/purchases/purchase_token: (403) Forbidden
If I make a validation of this purchase by the test form in Developers Console, everything is OK and Google API would send a response.
Requests to other API (for example Books API) works fine.
To work with API I use Google APIs Client Library for PHP. Authorization goes by Service Account. In Developers Console access to Google Play Android Developer API is on.
Ok I found the solution!
You must to connect your API with your app. You must go to your Google Play publish page (https://play.google.com/apps/publish) and invite a user with the service account email in Settings->User account & rights->Invite new user and give it the privileges of "View financial reports".
Thanks works for me, good luck!