Google Drive: Rest API access to another users shared folder in a google drive account -
i developing web-app where-in users able create content in own google drive account , share others. allow app access folder shared (say, publically) user through drive rest api , present content other users of app. (to clarify, not want list or show files through google drive website read contents programmatically , process within app).
would such scenario possible google drive , if how should proceed setting up?
thanks in advance
ps: looked @ service account seems every user have register same app if want share contents of drive others through app. have got correct?
you asked long time ago... in case answer else opened page looking same solution.
let's you list files in way:
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
in some_page.html.erb code:
<% @result.each |f| %> <% if f.mimetype == 'application/vnd.google-apps.folder' %> <% if f.parents.any? %> <% f.parents.each |parent_root| %> <% if parent_root.is_root %> <!-- these folder in root of 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 folder in root of 'shared 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 |parent| %> <% if parent.isroot %> <!-- these files in root of 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 files in root of 'shared me' --> <%= image_tag f.icon_link %> <%= link_to f.title, f.alternate_link, class: 'btn btn-default btn-sm', :target => "_blank" %> <% end %> <% end %> <% end %>
Comments
Post a Comment