Fix "403 Forbidden" Error with Google Fusion Table REST API - json

Background
I've created a Google Fusion Table, and set it to be public.
I am trying to access the data inside with Google's Rest API.
I'm using an API key rather than OEmbed.
The table ID is 17I-oLcU_9RNosUEtUBMS-k4MlBDCKNvipL00DHBI, so my query ends up as:
https://www.googleapis.com/fusiontables/v2/query?sql=SELECT * FROM 17I-oLcU_9RNosUEtUBMS-k4MlBDCKNvipL00DHBI&key=APIKEY
Problem
I'm getting back a 403 Forbidden error. I've tested my API key with some of the samples on Google's website, and getting back working data. But when I put in my table ID, I get this:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
}
Question:
Is there something else I need to do?

The answer isn't well documented in Google's official documentation, but it turns out that there is another setting buried further down than Sharing Settings.
Go to:
File -> About this table
That will pop up an overlay. Click on the "Edit table information" link.
This will take you to a new page. From there, select the checkbox that says Allow Downloads.
Once I changed that, my error instantly disappeared.

I was creating and deleting tables through the api with an authorized service account. After doing bulk deletes http forbidden errors started returning. I added a retry to my delete function and spammed it a few more times. At which point the deletes completely failed.
After reading this post I used the flag to update the "isExportable" property of the existing tables. Only a few of the tables updated with each pass. The remaining update calls returned http forbidden errors.
Those that did update I could delete through the api. I'm now stuck with 10 tables that will not delete or update. I've created new tables with the "isExportable" set to "true" and they always delete fine.
It seems there is an issue with how "isExportable" is handled within fusion tables.
After 24 hours I checked back and the tables that were hung had been deleted. It would appear that a background process eventually took care of the deletes.
I hope this helps someone else.

Related

Error Inserting event on Google Calendar (GSUITE): Read timed out

We have an error trying to insert an event on a Google Calendar affecting diferents GSUITE basic accounts.
We are using a ServiceAccount to create the credential for the connection, and this is working fine, we can read, insert or delete events on each Calendar account.
The problem started from two days ago when the code reach this point, it doesnt receive a response.
event = service.events().insert(calendarId, event).setSendNotifications(sendNotificationMail).execute()
We have tried to increment the connection and request timeout like this example (unsuccessfully):
https://developers.google.com/api-client-library/java/google-api-java-client/errors
After increment request timeout more than 60sec, we had this response:
503 Service Unavailable
{
"code" : 503,
"errors" : [ {
"domain" : "global",
"message" : "The service is currently unavailable.",
"reason" : "backendError"
} ],
"message" : "The service is currently unavailable.",
"status" : "UNAVAILABLE"
}
We have more than 20 accounts inserting events successfully, and start appearing only in few accounts, but we are afraid that it will expand.
The accounts doesn't have reach any limit of usage(an affected account only inserted 5 events).
If you can help me I would be very grateful.
Thank you
As mentioned above, using a service account for the Calendar API recently leads to errors, especially when sending notifications and creating events with invitees in general
Whilst the corresponding requests usually results in 403 errors and 503 errors are more often due to user errors or temporarily issues, I recommend you to adjust to the current workaround and use service accounts for the Calendar API only in conjunction with impersonation.
That is, enable in the Admin console domain-wide delegation, provide the necessary scope and implement in your code that the serviec account shall act on behalf of a domain user (e.g. the admin). This is the recommended procedure described in the documentaiton for Calendar API.

Cannot delete course Google Classroom API

I'm trying to delete a course using the "TRY THIS API" option in https://developers.google.com/classroom/reference/rest/v1/courses/delete I get the error:
"error": {
"code": 500,
"message": "Internal error encountered.",
"status": "INTERNAL"
}
}
Care should be taken when removing a teacher's account, because, as explained in the official documentation:
Before you remove a teacher's account, confirm that the teacher’s classes are no longer in use by students or co-teachers. Removing a teacher account without transferring ownership limits some class functionality.
Because of this, trying to remove a course owned by a deleted user results in a 500 error, as reported in Issue Tracker.
In normal conditions, as a G Suite admin, you should be able to transfer ownership of the class, but since the class functionality is limited, you might not be able to add a new teacher to transfer ownership to. Because of this, the FAILED_PRECONDITION error you are getting might be due to the course being in a non-modifiable state (here you can see the possible reasons behind FAILED_PRECONDITION).
Reference:
Issue Tracker: 500 Internal Server Error when trying to delete courses created by users that have been deleted
Before you remove a teacher account
Transfer ownership of the class
Request Errors: FAILED_PRECONDITION

Set up Google Calendar V3 API Push notification via my Google Apps script

I want to use Google CAL API v3 to watch multiple calendars and thus to update all those events from those calendars to a Master Calendar, so I need to use WATCH/PUSH notification in order that whenever there is a new event in those cal’s, those events shd be automatically be pushed/created in my master calendar.
But, I am facing the following issue :Under APIs Explorer. Most of the services return 200 OK, except the Watch request not working.
Services > Calendar API v3 > calendar.events.watch
i got the below request and response
Request
POST https://www.googleapis.com/calendar/v3/calendars/mailid%40domain.com/events/watch?key={YOUR_API_KEY}
{
}
Response
400 OK
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "entity.resource"
}
],
"code": 400,
"message": "entity.resource"
}
}
And then i followed as per the below google documentation
https://developers.google.com/google-apps/calendar/v3/push
Registering Your domain:
Step 1: Verify that you own the domain
Step 2: Register your domain
I verified my domain/notifications in google webmaster tools.
My verified domain look like this:
http://my-domain.com/notifications
And have added my domain name in the webhooks under the PUSH in Google Developer Console, as explained in the doc.
Is there anything i am missing here, plz is there an issue in SSL certificate fr my domain, how can i atleast test in the API explorer, so that i get a return code 200 OK. After that, I need to implement this push/WATCH via Google Apps Script.
Is there any documentation for apps script to use push notification.
Any hint, tip will help me, I am tired with this for the past 1 week in trial and error method.
In the request that you posted the body is empty. In the documentation there is an example where you need to provide the calendar ID, the web_hook and other information:
{
"id": "01234567-89ab-cdef-0123456789ab", // Your channel ID.
"type": "web_hook",
"address": "https://example.com/notifications", // Your receiving URL.
...
"token": "target=myApp-myCalendarChannelDest", // (Optional) Your channel token.
"expiration": 1426325213000 // (Optional) Your requested channel expiration time.
}
Add this information when creating the push notification.
For using apps script you can use URLfetch service with the method "fetch()" then you would need to provide the parameters mentions and make the call as a POST.
Hope this helps.
UPDATE: I will write here to have more space.
Push notifications work in this way.
-You create a push notification with the id, the resource you want to watch, the address where you want to receive the notification and the optional parameters.
-if successful, the server will watch that resource and will send a notification to the address mentioned in the request describing the changes when a change is made to the resource.
-The server needs to know that you received the notification, so from the address mentioned in #1, you need to tell the server that you received the notification returning a HTTP 200 response. (for this you need an app that is listening to the notifications and sending the responses)
for your questions
1.- As the server will make a HTTP request to a url (your web_hook address) Google requires it to be secure, that's why it is required to be HTTPS.
2.- Yes, without that url you won't be able to receive the notification.
3.- Google also needs to verify that the url you provided is actually yours, so you will need to provide the url, then Google will provide you a file, you have to make this file available in that url, then Google will call the url an will retrieve that file. Then you can prove that the URL is yours. I'm not sure if this step can be done with apps script. You can actually deploy a script as web app but i'm not sure if you can use it for this purpose.(here you can find more info and different ways to verify the url)
4.- That's created by yourself. In the documentation is pointed out the recommendations for it.
I hope this clarifies your questions.
You can check here how push notifications work, this example is for Drive but the concept is the same.

Google Drive Error: Registered app required, either through authentication token or key param

Suddenly today requests from my service attempting to insert a file into Google drive via the Drive API started to receive a 400 error. The error indicates that a registered app is required, full error below. An application was already registered in my Google Cloud console, however the applications name did not match the application name that was used by my service. I renamed the services application name, however the error continues.
400 Bad Request
{
"code": 400,
"errors": [
{
"domain": "global",
"message": "Registered app required, either through authentication token or key param.",
"reason": "required"
}
],
"message": "Registered app required, either through authentication token or key param."
}
Is there something else that needs to be setup, or could this be a delay in the renaming of the service?
EDIT: I'm able to list, update and download files however I cannot insert.
This same issue just started to happen to us today - and we made no changes. I (think I) submitted a bug report to Google about this. Will keep digging..
UPDATE: I created a new project with private key and client ID/email and I get the same error with this new project as well. This appears to be some bug with Google Drive API service.
It happens today on my app too. I guess their service is having problem today

Daily Limit Error Message with Google Drive

I am getting an error message when trying to use the Google Drive API to get a file. Using Python, the line that causes error is:
file = service.files().get(fileId=googleDriveFileId).execute()
The error message is:
HttpError: <HttpError 404 when requesting
https://www.googleapis.com/drive/v2/files/0B6Cpn8NXwgGPSE8zQW10XzJMc0k?alt=json returned
"File not found: 0B6Cpn8NXwgGPSE8zQW10XzJMc0k">
Basically saying "File not found"
However, if I put the URL being requested into browser, I get a different error message:
https://www.googleapis.com/drive/v2/files/0B6Cpn8NXwgGPSE8zQW10XzJMc0k
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit Exceeded. Please sign up",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit Exceeded. Please sign up"
}
}
Neither of these error messages seem correct to me. I know the file is there. Here is a working link to the same file retrieved from "Share Link" in the Google Drive UI:
https://docs.google.com/file/d/0B6Cpn8NXwgGPSE8zQW10XzJMc0k
I have also checked the Quota reports in the api console, and we are at 0% usage.
Any ideas what is going on here?
Thanks
I had similar errors following the python quickstart.
It turned out I had correctly created an API key etc, however had missed step 2:
Select the Services tab in your API project, and enable the Drive API.
Having used the API before I skipped along and missed this crucial point.
Both of the error messages did not have accurate info. The problem was related to permissions. I was using Google Picker to upload the files in question, but these files were not automatically available to the API because of permissions. I thought they would be according to documentation.
I solved problem by setting the permissions for the folder the images are being uploaded to for "Public" using the Google Drive UI. Now my app has permission to access the uploaded files.
While setting files permission to "Public" is okay in my case, as these files are meant to be public, I know this would not be acceptable in all cases. Can someone please shed light on how to handle this problem.... so that files uploaded with Google Picker automatically have the permission to be accessed by the API without setting folder permissions to "Public"?
The messages were accurate.
In the first case, because you don't have permission, Google gives a file not found. This is a standard security measure, rather than leak information by confirming the file exists.
In the second case, you called the API without an Authentication Header, so Google treats you as an unregistered and unauthorised app, which for some Google APIs is OK, up to a a daily quota. In the case of Drive, that daily quota is zero.
I agree it's not intuitive, and I'm sure many developer man years have been wasted (mine included), but it is accurate.
To answer your question about why the uploaded file is inaccessible, check that you have requested the correct scope, and that you are using the correct client id and mime type when doing the upload.