Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Drive API with ColdFusion

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.

like image 798
pawangera Avatar asked Jul 11 '26 13:07

pawangera


1 Answers

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

Authorization:  Bearer ya29.AHES6ZRosLBEnyGGH9EysIrAB7Z
like image 73
pinoyyid Avatar answered Jul 14 '26 13:07

pinoyyid