3

I started to work on Google Drive API with ColdFusion and I am stuck to upload the file using ColdFusion. I have done with the registration of new project, getting client and client secret and I am successfully able to get the accessToken but somehow I am not able to upload the file on the google drive.

Here is the code to get the code and accesstoken

<cfoutput>  
  <cfset request.oauthSettings = {
   scope = "https://www.googleapis.com/auth/drive",      client_id = "clientid",
   client_secret = "clientsecret",
   redirect_uri = "link"}
  />      
  <!--- create login url --->
  <cfset loginURL = "https://accounts.google.com/o/oauth2/auth?scope=" 
   & request.oauthSettings["scope"]
   & "&redirect_uri=" & request.oauthSettings["redirect_uri"]
   & "&response_type=code&client_id=" & request.oauthSettings["client_id"]
   & "&access_type=offline"
  />

  <a href="#loginURL#">Login with Google account that has access to analytics</a>

  <cfif isDefined("URL.code") AND URL.code NEQ "access_denied">     
    <cfhttp url="#arguments.gaOauthUrl#" method="post">
     <cfhttpparam name="code" type="formField" value="#arguments.code#">
     <cfhttpparam name="client_id" type="formField" value="clientid">
     <cfhttpparam name="client_secret" type="formField" value="clientsecret">
     <cfhttpparam name="redirect_uri" type="formField" value="link">
     <cfhttpparam name="grant_type" type="formField" value="authorization_code">
    </cfhttp>       
  </cfif>    
</cfoutput>

I am using the following code to upload the file, I know I have to pass some more parameters to make it correct but I don't know what are that parameters.

<cfhttp url="https://www.googleapis.com/upload/drive/v2/files?uploadType=media" method="post">
  <cfhttpparam name="Content-Type" type="formField" value="text/plain">
  <cfhttpparam name="Authorization" type="formField" value="#session.ga_accessToken#">            
</cfhttp>

I am trying to find out in the google docs but no luck; there is no documentation for ColdFusion. Please let me know the other parameters if someone has some clue about this area.

duncan
  • 31,401
  • 13
  • 78
  • 99
pawangera
  • 61
  • 1
  • 4
  • The parameters are all listed here: https://developers.google.com/drive/v2/reference/files/insert – duncan Nov 12 '13 at 09:20
  • Hi Duncan, Thanks for help but there is no library for ColdFusion and I just need to know how to pass the path of the file. I would like to upload word file. Any help would be highly appreciated. Thanks in Advance – pawangera Nov 12 '13 at 13:16
  • I think you would just need to add a parameter for the 'body' like so: `` - see http://stackoverflow.com/questions/14124469/upload-files-to-google-drive-using-coldfusion-stuck – duncan Nov 12 '13 at 13:28

1 Answers1

2

You aren't setting the Authorization header correctly. It should be

Authorization:  Bearer ya29.AHES6ZRosLBEnyGGH9EysIrAB7Z
pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • Thanks for giving this vital info. I added the Bearer text in the authorization with access_token but still I need one more parameter that is the path of the file which I would like to upload but I have no clue how can I pass it. – pawangera Nov 12 '13 at 13:10
  • I have changed the authorization code with Bearer and accesstoken. – pawangera Nov 12 '13 at 13:17