Getting error 500 when using the Google Drive API to update permissions

I get 500 errors when I try to grant access to any file. I don't want to send email when a file is shared with someone. I want to stop notification emails.

  Insert insert = service.permissions().insert(fileId, newPerm);
  insert.setSendNotificationEmails(false);
  newPerm = insert.execute();


        500 OK
            {
            "code" : 500,
            "errors" : [ {
            "domain" : "global",
            "message" : "Internal Error. User message: \"An internal                                                     error has occurred which prevented the sharing of these item(s): fileame\"",
           "reason" : "internalError"
            } ],
          "message" : "Internal Error. User message: \"An internal error has occurred which prevented the sharing of these item(s): filename\""
            }

      

Appreciate any suggestion.

+3


source to share


3 answers


I started getting this problem, but I managed to get around it by introducing a pause between clicking the file and pasting the permissions.

my "workflow" (using HTTP messages, not rest client):

  • Click the file.
  • Get fileId from Google Drive API response.
  • Send payload to insert permission using fileId

I always got a 500 Internal Error in step 3; the file has always been successfully clicked.



In my initial debug, when I step over, I try to push the same file to google again and it will return the same file as in previous attempts with the same file (so the Google Drive API should repeat the file the same) ...

But when I tried to use subsequent permissions (still debugging) with the same file, it was ALWAYS successful.

So, I just imagined a 20 second pause between clicking on the file and pasting the permissions, which did the trick (since timing is not critical in my application).

There must be some kind of replication lag (or "time_til_permissions_can_be_inserted") in Google Drive. It's hard to believe seeing him google, but hey.

+2


source


As another answer to this question, @ eversMcc had the right idea: pause for a little. The error stems from Google Drive being busy processing this file (by creating it, clicking it to make it globally available, or otherwise updating it). After the action flow is down, adding additional users to the document shouldn't be a problem.

You can see from this API disk documentation page a description of the error you got (500), as well as the recommended course of action which is to implement an exponential back off, which really just says you should pause a bit before retrying try and extend this delay every time you get the same error. Here's the same recommendation in the API Drive docs .

While @eversMcc implemented a 20 second pause, you don't need to use a fixed grace period, so exponential is useful. Why wait 20 seconds when only 4 or 8 are enough? Another resource is the descriptive blog post . If you don't want to implement it yourself, you can try to find something similar to these (Python based) retrying or backoff . Check out this related SO Q&A if you want an example of your own.



Use the Drive API to add permissions or any file related operations such as sharing, copying, import / export, etc., but for any document- oriented operations, say with Sheets tables, you will be using the Google Sheets API .

NOTE 1: there was a similar issue a year before this post, but it was fixed according to this SO Q&A .

NOTE 2 .: Drive API v2 permissions.insert()

changed names to permissions.create()

in v3 - see migration guide for more details

+1


source


This is most likely a transient bug in the Drive API framework. Sometimes you may encounter similar behavior caused by network or server problem at the end of google.

Unfortunately, there is very limited information available about these types of errors. The intended strategy would be execution and exponential rejection, as explained here here and in more detail here .

In some (strange) cases, the problem can last longer than expected, which is pain and frustration for the developer, but eventually it will go away, hopefully within 24-48 hours, and everything will return to normal if the error persists for a long time, you must request a trace token for the Drive API support agent, which will generate additional information internally that can be analyzed by an engineer.

-3


source







All Articles