Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails驱动Rest Api |使用google Api客户端gem共享文件_Ruby On Rails_Ruby_Google Drive Api - Fatal编程技术网

Ruby on rails Rails驱动Rest Api |使用google Api客户端gem共享文件

Ruby on rails Rails驱动Rest Api |使用google Api客户端gem共享文件,ruby-on-rails,ruby,google-drive-api,Ruby On Rails,Ruby,Google Drive Api,我正在构建一个实现一些驱动功能的应用程序。现在,我正在尝试使用GoogleAPI ruby客户端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.authori

我正在构建一个实现一些驱动功能的应用程序。现在,我正在尝试使用GoogleAPI ruby客户端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: "some@gmail.com")
@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."
 }
}


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

由于调试器指向@drive.create\u权限行,这意味着它正在该行中查找“type”权限。尝试添加字段值

type: "user", role: "writer"
这条线看起来是这样的:

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

如果我传递了一个权限对象,如文档所述,它不起作用,那么正确的形式和唯一为我工作的人是:

user_permission = {type: "user", role: "writer", email_address: "some@gmail.com"}
@drive.create_permission(current_user.fileId, user_permission, send_notification_email: false, fields: 'id', &callback)

如果有人在使用google javascript库,权限结构的权限创建上的字段名为“resource”

调试器指向@drive.create\u权限行不起作用,我认为错误与对象“per”有关。在这里您可以看到文档