很久以前你问过了......所以这是为了以防万一我的回答会帮助打开此页面的其他人寻找相同的解决方案。
让我们说你你列出这样的文件:
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 %>