Google drive api 在java桌面应用程序中使用parents参数在另一个文件夹中创建文件夹

Google drive api 在java桌面应用程序中使用parents参数在另一个文件夹中创建文件夹,google-drive-api,Google Drive Api,我试图通过设置parents属性的id在另一个文件夹中创建文件夹,但该文件夹未在其中创建。我需要java桌面应用程序的解决方案,但我找不到parents属性的正确语法,以便正确执行我的post请求(HttpPost对象是org.apache.http.client.methods.HttpPost) 有谁能告诉我我做错了什么,或者提出一个解决方案吗?我使用的是谷歌API Ruby客户端gem,可以在上找到 是一种返回并验证客户端和驱动器实例的方法。本质上,您使用令牌向发出post请求,如下所示:

我试图通过设置parents属性的id在另一个文件夹中创建文件夹,但该文件夹未在其中创建。我需要java桌面应用程序的解决方案,但我找不到parents属性的正确语法,以便正确执行我的post请求(HttpPost对象是org.apache.http.client.methods.HttpPost)


有谁能告诉我我做错了什么,或者提出一个解决方案吗?

我使用的是谷歌API Ruby客户端gem,可以在上找到

是一种返回并验证客户端和驱动器实例的方法。本质上,您使用令牌向发出post请求,如下所示:

{'refresh_token' => USERS_EXISTING_REFRESH_TOKEN,
'client_id' => 'YOUR_CLIENT_ID',
'client_secret' => 'YOUR_CLIENT_SECRET',
'grant_type' => 'refresh_token'}
然后就可以简单地实现如下方法:

def create_folder_within_folder(title, parent_folder_id)

    # INPUTS: a folder title (string) and parent_folder_id (string) 
    # OUTPUT: the file_id (string) of the newly created folder

    @client, @drive = authenticated_client_and_drive

    @folder = @drive.files.insert.request_schema.new({
        'title' => title,
        'description' => 'Your Description Here',
        'mimeType' => 'application/vnd.google-apps.folder',
        'parents' => [{"id" => parent_folder_id}]
    })

    @result = @client.execute(
      :api_method => @drive.files.insert,
      :body_object => @folder)

    return @result.data.id

end

希望这为您指明了正确的方向!

仔细检查父ID周围有多少引号非常感谢您的回答,但我需要一个java桌面应用程序的解决方案,这种方法不适用于我的情况。更具体地说,我必须为parents属性找到正确的语法,以便执行我的post request(HttpPost是org.apache.http.client.methods.HttpPost)。
{'refresh_token' => USERS_EXISTING_REFRESH_TOKEN,
'client_id' => 'YOUR_CLIENT_ID',
'client_secret' => 'YOUR_CLIENT_SECRET',
'grant_type' => 'refresh_token'}
def create_folder_within_folder(title, parent_folder_id)

    # INPUTS: a folder title (string) and parent_folder_id (string) 
    # OUTPUT: the file_id (string) of the newly created folder

    @client, @drive = authenticated_client_and_drive

    @folder = @drive.files.insert.request_schema.new({
        'title' => title,
        'description' => 'Your Description Here',
        'mimeType' => 'application/vnd.google-apps.folder',
        'parents' => [{"id" => parent_folder_id}]
    })

    @result = @client.execute(
      :api_method => @drive.files.insert,
      :body_object => @folder)

    return @result.data.id

end