Google G Suite Business Reports API configuration - google-api

I'm trying to configure Google Service Account (in developers console) to use it in my application to get Reports API.
I'm getting error - "Access denied. You are not authorized to read activity records". It seems some issue with configuration.
I created new Project and Service Account in Google Developers Console. Added Client ID in Admin Console Settings Manage API client access menu.
Maybe I missed something?
Please, help.
Server response is:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Access denied. You are not authorized to read activity records.",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Access denied. You are not authorized to read activity records."
}
}

You can try to call the .setServiceAccountUser("admins email address") as per described in this SO post if you haven't done yet.

Related

Google calendar api get error like "domain": "global", "reason": "notFound", "message": "Not Found"

I tried get list of event from calendar example from here.
No matter which property I
use, I always get the 404 "not found" error. Anyone can shed some light on this? Many thanks.
Request.
POST https://www.googleapis.com/calendar/v3/calendars/oneclapp.2021#gmail.com/events?
key=AIzaSyCGRPF0wSSBLndqdUftlbsDH9emHD_S-qg
Accept: "application/json"
Authorization: Bearer ya29.a0ARrdaM9PPHndl040qaXFmoSFGT9yRPWZs_yrTnYLAHQ0GF-UBvGc67S2L1m0O5OFIilq8oVGRuvw29NFwomtmUTBeHoABcIlaVD_p--4NVlBWCcXLBgfDjsF_5tvt4XRShd1itpe_9CULan9x6BV4TOyP__TkQ
Response
Response:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "not Found",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}
First off events.list is not HTTP Post its a HTTP GET
GET https://www.googleapis.com/calendar/v3/calendars/calendarId/events
Second assuming that you just miss wrote post and you are actually doing a http get.
Not found means just that the currently authenticated user does not have access to the calendar that you are trying to request events for. in this case oneclapp.2021#gmail.com
I recommend using primary to test that you can get the currently authenticated users primary calendar.
GET https://www.googleapis.com/calendar/v3/calendars/primary/events
It looks like you have not configured the OAuth 2.0 Client IDs correctly. We need to configure the OAuth client ID correctly and its type should be 'Web Application'. I was also getting the same error messages, but once I configured the OAuth ID, then it started working.
OAuth id type: Web Application
Permission scopes : https://www.googleapis.com/auth/calendar.readonly, https://www.googleapis.com/auth/calendar, https://www.googleapis.com/auth/calendar.events.readonly, https://www.googleapis.com/auth/calendar.events
Authorized redirect URIs: http://localhost
Here is the screenshot of the Google Calendar API project settings.

Tag Manager Client API: Unable to access Tag Manager content with API key

I would like to connect to the Tag Manager Client API to access some content in a container without having to log in.
This page mentions at the top that it "Requires authorization". However, I am using the contents of a container to store ad urls and the users of the website I'm working on shouldn't be asked to log in to Google for this.
What also makes me confused is that the "Try this API" UI let's me choose Credentials using:
Google OAuth 2.0
or API key
However, when I select "API key", I get a 401 error with the message: "Login Required".
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
Thanks
The "test this API" interface presents you with a choice that is not actually applicable.
The API documentation for the GTM API is quite unambiguous:
Your application must use OAuth 2.0 to authorize requests. No other
authorization protocols are supported. If your application uses Google
Sign-In, some aspects of authorization are handled for you.
So the problem seems to be that the "try this API" has a generic UI that gives you options that are not actually valid for each of the APIs where it shows up.

YoutubeAPI returns 401 Invalid Credentials error when try to upload video to youtube using Youtube Data API(V3)

I am trying to upload video to Youtube using Angular File Uploader,OAuth and Youtube Data API(v3) in Codeigniter project. But It always fails with 401 Invalid Credentials response. I tried creating a youtube channel as suggested by other answer but it didn't work for me.
This is my POST url structure
https://www.googleapis.com/upload/youtube/v3/videos?client_id={clientID}&access_token={accessToken}&part=snippet&mine=true
Please can someone explain me the procedure for do this successfully I am new to this.
Invalid Credentials means that The access token you're using is either expired or invalid. You should check the full error for more information. It normally looks something like this.
401: Invalid Credentials Invalid authorization header.
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization",
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
Videos: list is a public request this means that technically you only need an API key.
https://www.googleapis.com/upload/youtube/v3/videos?key=yourkey
You can use an access_token which was gained from Oauth2 authencation.
https://www.googleapis.com/upload/youtube/v3/videos?access_token=yourtoken
There is no need to add client_id this may be what is causing your problem.

Google DNS API & Gcloud Console Error

I'm using gcloud console for windows and have enabled the Google DNS API in the developer console. I have authenticated from the gcloud console, but when I try to do anything with the DNS api, I get the following error message:
{
"error": {
"code": 403,
"errors": [
{
"domain": "usageLimits",
"message": "Access Not Configured. Please use Google Developers Console to activate the API for your pro ject.",
"reason": "accessNotConfigured"
}
],
"message": "Access Not Configured. Please use Google Developers Console to activate the API for your project."
} } ERROR: (gcloud.dns.managed-zone.list) ResponseError: status=403, code=Forbidden, reason(s)=accessNotConfigured
message=Access Not Configured. Please use Google Developers Console to
activate the API for your project.
Has anyone else had this problem?
There are a number of things to look at including if you have enabled billing for your project. Follow the link for more information https://cloud.google.com/dns/getting-started

pageSpeedOnline.pagespeedapi().runpagespeed(..) function fails with error 403

I have tried to analyze url page using pageSpeedOnline.pagespeedapi().runpagespeed(..) api but fails with 403 "Forbidden". The api is enabled in the console and the billing is also enabled but I am blocked further since it always fails with 403. The billing was just enabled since a week back.
Below is the response of the curl request,
curl "https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=http://code.google.com/speed/page-speed/&key=API_KEY"
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "accessNotConfigured",
"message": "Access Not Configured. Please use Google Developers Console to activate the API for your project."
}
],
"code": 403,
"message": "Access Not Configured. Please use Google Developers Console to activate the API for your project."
}
}
Please help.
I got it resolved, by creating "Key for browser apps (with referers)" and used that API key in the project.

Resources