2015-06-26 68 views
1

我正在开发一个网络应用,用户可以在其自己的Google云端硬盘帐户中创建内容并与其他人共享。为了实现这个功能,我希望应用程序能够通过驱动器rest api访问该用户共享的文件夹(比如公开地),并将内容呈现给应用程序的其他用户。 (为了澄清,我不想通过谷歌驱动器网站列出或显示文件,但以编程方式阅读其内容并在应用程序内处理它)。Google云端硬盘:通过其他API访问Google云端硬盘帐户中的其他用户共享文件夹

这样的情况下可能与谷歌驱动器,如果是的话我应该如何继续设置它?

在此先感谢

PS:我看着服务帐户,但似乎每个用户将不得不如果他们想与其他人通过应用分享自己的驱动器的内容,注册相同的应用程序。我有这个正确的吗?

回答

0

很久以前你问过了......所以这是为了以防万一我的回答会帮助打开此页面的其他人寻找相同的解决方案。

让我们说你你列出这样的文件:

def google_files 

    client = Google::APIClient.new 
    client.authorization.access_token = Token.last.fresh_token 
    drive_api = client.discovered_api('drive', 'v2') 

    @result = Array.new 
    page_token = nil 
    begin 
    parameters = {:orderBy => 'folder'} 
    if page_token.to_s != '' 
     parameters['pageToken'] = page_token 
    end 
    api_result = client.execute(
     :api_method => drive_api.files.list, 
     :parameters => parameters) 
    if api_result.status == 200 
     files = api_result.data 
     @result.concat(files.items) 
     page_token = files.next_page_token 
    else 
     puts "An error occurred: #{result.data['error']['message']}" 
     page_token = nil 
    end 
    end while page_token.to_s != '' 
    @result 
end 

在你some_page.html.erb此代码:

<% @result.each do |f| %> 
    <% if f.mimeType == 'application/vnd.google-apps.folder' %> 
     <% if f.parents.any? %> 
      <% f.parents.each do |parent_root| %> 
       <% if parent_root.is_root %> 

        <!-- these are your folder in the root of your disk - 'My Disk' --> 
        <%= image_tag f.icon_link %> <%= link_to f.title, f.alternate_link, class: 'btn btn-default btn-sm', :target => "_blank" %> 
       <% end %> 
      <% end %> 
     <% else %> 

      <!-- these are your folder in the root of the 'Shared with me' --> 
      <%= image_tag f.icon_link %> <%= link_to f.title, f.alternate_link, class: 'btn btn-default btn-sm', :target => "_blank" %> 
     <% end %> 
    <% else %> 
     <% if f.parents.any? %> 
      <% f.parents.each do |parent| %> 
       <% if parent.isRoot %> 

        <!-- these are your Files in the root of your disk - 'My Disk' --> 
        <%= image_tag f.icon_link %> <%= link_to f.title, f.alternate_link, class: 'btn btn-default btn-sm', :target => "_blank" %> 
       <% end %> 
      <% end %> 
     <% else %> 

      <!-- these are your Files in the root of the 'Shared with me' --> 
      <%= image_tag f.icon_link %> <%= link_to f.title, f.alternate_link, class: 'btn btn-default btn-sm', :target => "_blank" %> 
     <% end %> 
    <% end %> 
<% end %> 
相关问题