vendredi 8 mai 2015

can't download file from google drive with ruby

I'm trying to get my rails controller set up to download a file from google drive following the code at - http://ift.tt/Q3fmNw

I have the following rails code

def download_file(client, file)
  if file.download_url
    result = client.execute(:uri => file.download_url)
    if result.status == 200
      return result.body
    else
      puts "An error occurred: #{result.data['error']['message']}"
      return nil
    end
  end
end

def attachExternalResume
  # read remote url to file
  file_id = params[:fileId]
  client = Google::APIClient.new
  drive = client.discovered_api('drive', 'v2')
  result = client.execute(
    :api_method => drive.files.get,
    :parameters => { 'fileId' => file_id}
  )
  if (result.status == 200)
    p download_file client, result.data
  end
end

This is being called from my javascript front end using the google picker. The user authorizes my app through the google picker and selects a file which results in my angular javascript posting the file id to my rails method. In the rails code I'm getting the following error - Missing access token.

It seems like even though the user has authorized the app on the front end, that authorization isn't making its way through to the rails side. Anyone know how I can get the authorization all the way through the process?

Aucun commentaire:

Enregistrer un commentaire