Google Drive API Java权限500内部错误

时间:2012-12-13 12:34:56

标签: google-drive-api google-drive-realtime-api

我有下一种方法来共享Google云端硬盘文件:

public static boolean shareFile(HttpServletRequest httpReq, String fileId, String user, String rol, boolean commenter) {        
    Drive service = getService(httpReq) ;

    if (service != null){   
        Permission newPermission = new Permission();

        newPermission.setValue(user);
        newPermission.setType("user");
        newPermission.setRole(rol);

        if (commenter)
            newPermission.setAdditionalRoles(Arrays.asList("commenter"));

        try {      
            service.permissions().insert(fileId,  newPermission).execute();
            return true;

        } catch (Exception e) {      
            System.out.println("An error occured: " + e);   
        }
    }
    return false;

}

当变量评论者为假(我们没有设置addiotional角色)时,一切正常,但如果我希望用户有角色“读者”和“评论者”,我会得到下一个错误:

    An error occured: com.google.api.client.googleapis.json.GoogleJsonResponseException: 500 Internal Server Error
    {
        "code" : 500,
        "errors" : [ {
            "domain" : "global",
            "message" : "Internal Error",
            "reason" : "internalError"
        }   ],
        "message" : "Internal Error"
    }

有没有人遇到过这种问题?

1 个答案:

答案 0 :(得分:1)

如果传递 id 字段不正确,我会遇到此类错误。 奇怪的错误代码,我觉得像4XX这样的东西在这里更合适(不是500)。

100%可重复。

请求:

POST https://www.googleapis.com/drive/v2/files/0B28tlN6SgYRaNVRFRENpRFN3bGs/permissions?key={YOUR_API_KEY}


{
 "role": "reader",
 "type": "user",
 "id": "16887416236869940585"
}

响应:

500 Internal Server Error

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "internalError",
    "message": "Internal Error"
   }
  ],
  "code": 500,
  "message": "Internal Error"
 }
}

希望Google Drive API错误消息提供更多信息(500内部服务器错误)。