2017-01-09 85 views
0

我正在构建一个实现一些驱动器功能的应用程序。现在我试图使用google-api-ruby-client gem共享一个文件。我有一些麻烦使用下一个代码。Rails Drive Rest Api |使用谷歌api客户端共享文件gem

#Here, I create a DriveService object and I authorize it. 
#This works fine. In my app I list drive files well. 
@drive = Google::Apis::DriveV3::DriveService.new 
@drive.authorization = @token[:access_token] 

#Here, first I create a permission object with some parameters 
#Then I call create_permission to share the file to a other user 
per=Google::Apis::DriveV3::Permission.new(type: "user", role: "writer",email_address: "[email protected]") 
@drive.create_permission(file_id:"0B8XBWuVEmvN8YS01OXNUcHhOYWs",permission_object: per, fields: "id", &callback) 

当我执行这个代码,回调表明这一点:

{ 
"error": { 
"errors": [ 
    { 
    "domain": "global", 
    "reason": "required", 
    "message": "The permission type field is required.", 
    "locationType": "other", 
    "location": "permission.type" 
    } 
    ], 
    "code": 400, 
    "message": "The permission type field is required." 
} 

}

我解决不了这个错误。有人能帮我吗?

+0

调试器指向@ drive.create_permission行 –

回答

0

由于调试器指向@ drive.create_permission行,这意味着它正在寻找该行的'type'权限。试着增加你的字段值

type: "user", role: "writer" 

该行因此它看起来就像这样:

@drive.create_permission(file_id:"0B8XBWuVEmvN8YS01OXNUcHhOYWs",type: "user", role: "writer", permission_object: per, fields: "id", &callback) 
+0

不起作用,我认为它与对象“per”有关的错误。 http://www.rubydoc.info/github/google/google-api-ruby-client/Google/Apis/DriveV3/DriveService。在这里你可以看到文档 –

0

我不知道为什么,如果我通过一个权限对象,像文件说,这不作品,所以正确的形式,谁对我的作品的只是它

user_permission = {type: "user", role: "writer", email_address: "[email protected]"} 
@drive.create_permission(current_user.fileId, user_permission, send_notification_email: false, fields: 'id', &callback) 
0

的情况下,任何人使用谷歌JavaScript库,在许可的字段名称的权限结构创建的“资源'