0

Using Google Apps for Education, I create and share folders for pupils and staff. This is done using server-side-flow, since we may need to increase storage. When sharing some folders, it works, but when sharing others, I get Internal Error 500. Sometimes this happens for the vast majority of folders, but rarely for all.

As an example, I created folders for approx. 1000 users, and sharing each one failed. They are shared with type=user, role=writer.

Also, as happened today, there are days when sharing causes no errors at all, and I could create and share folders for all users.

Does anyone have any ideas? Thanks, Michael.

I call shareFolder like this: shareFolder(, , "user", "writer", true);

public boolean shareFolder(String fileId, String sharerEmail, String type, String role, boolean forcesharing) {

    if (sharerEmail == null || sharerEmail.length() == 0) {
        return true;
    }

    sharerEmail = sharerEmail.toLowerCase();
    Permission perm = sharedAlready(fileId, sharerEmail, type, role);

    if (forcesharing && perm == null) {
        logger.info("File id " + fileId + " will be force shared with " + sharerEmail + ".");
        Permission permission = new Permission();
        permission.setValue(sharerEmail);
        permission.setEmailAddress(sharerEmail);
        permission.setType(type);
        permission.setRole(role);

        return insertSharingperm(fileId, permission);
    } else if (forcesharing) {
        // I do this in the hope that it my have an effect, but I'm beginning to doubt it.
        // There seems to be a problem with sharing the class folders with the class email, as readers.
        return updateSharingperm(fileId, perm);
    } else {
        if (perm != null) {
            logger.info("File " + fileId + " already shared with " + sharerEmail + ".");
            return true;
        } else {
            Permission permission = new Permission();
            permission.setValue(sharerEmail);
            permission.setEmailAddress(sharerEmail);
            permission.setType(type);
            permission.setRole(role);

            return insertSharingperm(fileId, permission);
        }
    }
}



public boolean insertSharingperm(String fileId, Permission perm) {
    try {
        if (null != executeWithEB(service.permissions().insert(fileId, perm))) {
            logger.info("File id " + fileId + " shared with " + perm.getEmailAddress() + ".");
            return true;
        } else {
            logger.warning("File id " + fileId + " not shared with " + perm.getEmailAddress() + ".");
            return false;
        }

    } catch (GoogleJsonResponseException e) {
        logger.severe("Failed. Code: "
                + e.getDetails().getCode() + "\nMessage: "
                + e.getDetails().getMessage() + " FileID=" + fileId
                + " SharerEmail=" + perm.getEmailAddress() + " Type=" + perm.getType()
                + " Role=" + perm.getRole());
    } catch (IOException e) {
        logger.severe("Failed:" + e.getMessage());
    } catch (InterruptedException e) {
        logger.severe("Failed:" + e.getMessage());
    }

    return false;

}
  • Possible duplicate of http://stackoverflow.com/questions/15685335/google-drive-files-list-500-error? – DavidPostill Jul 25 '14 at 12:37
  • @DavidPostill: This is not, as far as I can tell, a duplicate. My problem is, that I sometimes get to share a folder, and sometimes not. I do use exponential backoff, for 403 and 503, but not 500, as per recommendations. – michael neidhardt Jul 26 '14 at 13:53
  • Am running the program again today, and some folders get shared, while for others I get 500 internal error. Puzzling... – michael neidhardt Jul 26 '14 at 13:56

0 Answers0