2

I am using the CFC for the Google Calendar V3 API by billeatman. I have integrated it successfully in my pages, where I go to login and authenticate and start working. My trouble starts when the authentication expires, even when the session is still active in my website.

I tried storing the structure returned by the Google API along with the Access_token and refresh_token in the database table. After storing, I am just confused. How do I call it? The above GIT Code just says like this:

<cfset application.oauth2.refreshToken() />

The function has the following code:

<cffunction name="RefreshToken" access="public" output="false" hint="I take the refresh_token from the authorization procedure and get you a new access token.">
    <cfset var strURL = base_auth_endpoint & "token">
    <cfhttp url="#strURL#" method="POST">
        <cfhttpparam name="client_id" type="formField" value="#variables.client_id#">
        <cfhttpparam name="client_secret" type="formField" value="#variables.client_secret#">
        <cfhttpparam name="refresh_token" type="formField" value="#getTokenStruct().refresh_token#">
        <cfhttpparam name="grant_type" type="formField" value="refresh_token">
    </cfhttp>
    <cfreturn manageResponse(cfhttp.FileContent)>
</cffunction>

But I am lost about how I pass the token I stored in my database to refreshToken. So what I tried is, calling the following two functions:

<cfset application.oauth2.SetRefresh_token('#getaccess.refreshtoken#')>
<cfset application.oauth2.SetAccess_token('#getaccess.accesstoken#')> 

An error is thrown at this section:

<cfset application.oauth2.SetAccess_token('#getaccess.accesstoken#')>

It says "Method not found in the CFC". I am lost. How do I keep the oauth2 alive for the google calendar, until I am logged out.

<cffunction name="SetAccess_token" access="private" output="false" hint="setter for oauth access_token">
   <cfargument name="access_token" type="string" required="true">
   <cfset getTokenStruct()['access_token'] = arguments.access_token>
</cffunction>

<cffunction name="SetRefresh_token" access="public" output="true" hint="setter for oauth refresh_token">
   <cfargument name="refresh_token" type="string" required="true">
   <cfset getTokenStruct()['refresh_token'] = arguments.refresh_token>
</cffunction>
Leigh
  • 28,765
  • 10
  • 55
  • 103
JJN
  • 21
  • 1
  • any Update from any Experts, How can i proceed with this – JJN Jul 15 '15 at 10:36
  • Sorry, I couldnt find any examples in CFC. But you can check these links http://stackoverflow.com/questions/15905104/automatically-refresh-token-using-google-drive-api-with-php-script and http://www.jensbits.com/2012/04/05/google-analytics-reporting-api-using-oauth-2-with-coldfusion/ which are in python. Also, you check oauth flow here https://developers.google.com/oauthplayground/ – SGC Jul 17 '15 at 21:40
  • it seems this api is incomplete and left for the users to play with it, i had to switch back to @ray cfc, which seems a better option to me as of now – JJN Jul 21 '15 at 11:22

1 Answers1

0

The message, "Method not found in cfc" is because you are calling a private method, SetAccess_token, from outside of the cfc. Access="private" means it cannot be called from outside the cfc because its scope is private to the class. Change the function access to access="public" and you can call it as you are, classPath.publicFunction()

Community
  • 1
  • 1