https://www.googleapis.com/discovery/v1/apis/analytics/v4/rest
google-api-python-client version: 1.7.8I can confirm the 404.
Hi @blairg23! Do you know if there was a v4 previously, and when this started to 404? Is it possible you want to use the Analytics Reporting API rather than the Google Analytics API?
See discovery document.
analytics versions:
v2.4preprod, v3alphapreprod, v3preprod, v2.4, v3
analyticsreporting versions:
v4
You are correct, we are using the Analytics Reporting API v4.
In that case it looks like the restUrl is now https://analyticsreporting.googleapis.com/$discovery/rest?version=v4. That may be a recent change.
We're using the from googleapiclient.discovery import build import to implement the Analytics API service build. From there, you can see the following:
DISCOVERY_URI = ('https://www.googleapis.com/discovery/v1/apis/'
'{api}/{apiVersion}/rest')
V1_DISCOVERY_URI = DISCOVERY_URI
V2_DISCOVERY_URI = ('https://{api}.googleapis.com/$discovery/rest?'
'version={apiVersion}')
This was our working code that is no longer working:
```
def _build_analytics_api(self, version=4):
"""Builds the Google Analytics Api connection."""
credentials = client.OAuth2Credentials(
client_id=self._client_id,
client_secret=self._client_secret,
access_token=self._access_token,
refresh_token=self._refresh_token,
token_expiry=time.time() - 10,
token_uri=GOOGLE_TOKEN_URI,
user_agent='tomis',
)
http_client = httplib2.Http()
credentials.refresh(http_client)
credentials.authorize(http_client)
return build('analytics', f'v{version}', http=http_client)
Also this:
GOOGLE_TOKEN_URI = 'https://accounts.google.com/o/oauth2/token'
```
@blairg23 when did this start to 404 for you?
It looks like the v4 has a separate name ('analyticsreporting' instead of 'analytics'). I unfortunately don't have much context on the change.
Please use the name 'analyticsreporting' to build the service if you're using the v4.
Today, first event appears to be Jul 10, 2019 9:31:34 PM UTC
Can confirm: https://www.googleapis.com/discovery/v1/apis/analyticsreporting/v4/rest is working. Unsure why the old URL used to be working... will change code and test.
My theory is this bug originated due to old Analytics documentation that had that analytics build example in it that was copy/pasta'd into our code and just happened to work for a year and a half due to a coincidental bug that allowed the old URL to function with https://www.googleapis.com/discovery/v1/apis/analytics/v4/rest instead of https://www.googleapis.com/discovery/v1/apis/analyticsreporting/v4/rest
My guess is that once Google discovered the bug, they patched it, causing the 404 to start just by happenchance today. It does not appear to be a bug in google-api-python-client.
Hi @blairg23 Thanks for working through this and happy you have been unblocked.
Can you confirm that this did work before? If so, do you have an idea of how long? Just making sure to gather details while it is still fresh on your mind.
Thanks!
I just stumbled upon this.
I can confirm this worked before, used it since at least april 2017.
The quick start documentation is a little confusing. It uses build('analytics', 'v4') but overrides the discovery URL so the serviceName paramter of build has no effect.
@CerealP0rt
Thank you for taking the time to comment! I filed an issue on the team that maintains that quickstart. For anyone stumbling on this issue, please do:
from googleapiclient import discovery
service = discovery.build('analyticsreporting', 'v4')