I am trying to get temp_token for credly API's badge builder SDK. I am using ColdFusion as server side language. My code look like,
<cfhttp method=”post” result=”objGet”
url=”https://developers.credly.com/badge-builder/code” >
<cfhttpparam type=”formfield” name=”access_token” value=”my_access_token” />
</cfhttp>
As well as, I have tried
<cfhttp method=”post” result=”objGet”
url=”https://developers.credly.com/badge-builder/code” >
<cfhttpparam type="header" name="Authorization" value="access_token=(my_access_token)” />
</cfhttp>
<cfhttp method=”post” result=”objGet”
url=”https://developers.credly.com/badge-builder/code” >
<cfhttpparam type="header" name="access_token" value="(my_access_token)” />
</cfhttp>
<cfhttp method=”post” result=”objGet”
url=”https://developers.credly.com/badge-builder/code” >
<cfhttpparam type="header" name="access_token" value="my_access_token” />
</cfhttp>
All of them are giving me response as,
{
“success”:false,
”error”:”You must pass an access_token to retrieve a badge builder embed code”
}
Am I missing something?
Update:
I have checked their official wordpress plugin, they are using type as body. I have tried that too, but gave the same result.
Related
I'll keep this short. I have OAuth working with the Google Photos API. I am able to return albums and media items but not album specific media items.
Below I've done three requests. The first two work while the third does not.
Note: In the third request I've taken the albumID from the results returned in the first request.
<!--- This works --->
<cfhttp method="GET" charset="utf-8" url="https://photoslibrary.googleapis.com/v1/albums" result="res">
<cfhttpparam name="Authorization" type="header" value="OAuth #application.oauth2.GetAccess_token()#" />
</cfhttp>
<cfdump var="#deserializeJSON(res.filecontent)#">
<!--- This works --->
<cfhttp method="GET" charset="utf-8" url="https://photoslibrary.googleapis.com/v1/mediaItems" result="res">
<cfhttpparam name="Authorization" type="header" value="OAuth #application.oauth2.GetAccess_token()#" />
</cfhttp>
<cfdump var="#deserializeJSON(res.filecontent)#">
<!--- This doesn't. I get a 404 for this --->
<cfhttp method="POST" charset="utf-8" url="https://photoslibrary.googleapis.com/v1/mediaItems:search" result="res">
<cfhttpparam name="Authorization" type="header" value="OAuth #application.oauth2.GetAccess_token()#" />
<cfhttpparam name="albumId" type="formfield" value="AHeArAbj3EfLJqs23FHD9SWuReCaaPA0VBZxw6HNwL752bJr5X882_ZJnitk7kjZJwtzXvrw6hp2" />
</cfhttp>
<cfdump var="#res#">
This is the result I get for the last request;
What is wrong with the last request I am making? I am trying to use this API call: https://developers.google.com/photos/library/reference/rest/v1/mediaItems/search
I am trying to use the following code to access the Twilio Rest API to retrieve a list of incoming calls to my twilio number for a given date range.
https://www.twilio.com/docs/api/rest/call
<cfhttp url="https://api.twilio.com/2010-04-01/Accounts/xxxxxxxxxxxxxxxxx/Calls" method="get" resolveurl="no" username="xxxxxx" password="xxxxx1">
<cfhttpparam name="To" type="url" value="myphone">
<cfhttpparam name="StartTime>=" type="url" value="2015-05-01">
<cfhttpparam name="StartTime<" type="url" value="2015-06-01">
</cfhttp>
When I try to connect with the above, I get a "Connection" error in coldfusion. It doesn't like the ">". I have also tried to put the StartTime> into a variable perform urlencodedformat() on it, but it didn't give the desired result.
When I query an individual day it works fine.
<cfhttp url="https://api.twilio.com/2010-04-01/Accounts/xxxxxxxxxxxxxxxxx/Calls" method="get" resolveurl="no" username="xxxxxx" password="xxxxx1">
<cfhttpparam name="To" type="url" value="myphone">
<cfhttpparam name="StartTime" type="url" value="2015-05-01">
</cfhttp>
Based off Twilio code examples (I was referencing PHP examples) it appears the the variable name can be StartTime>, StartTime>=, StartTime<, StartTime<=.
In you code, you are calling the "StartTime"
<cfhttp url="https://api.twilio.com/2010-04-01/Accounts/xxxxxxxxxxxxxxxxx/Calls" method="get" resolveurl="no" username="xxxxxx" password="xxxxx1">
<cfhttpparam name="To" type="url" value="myphone">
<cfhttpparam name="StartTime>=" type="url" value="2015-05-01">
<cfhttpparam name="StartTime<" type="url" value="2015-06-01">
</cfhttp>
As per https://www.twilio.com/docs/api/rest/call, you should use StartTime & EndTime. I am able to dump the httpResponse with the below code:-
<cfhttp url="https://api.twilio.com/2010-04-01/Accounts/xxxxxxxxxxxxxxxxx/Calls" method="get" resolveurl="no" username="xxxxxx" password="xxxxx1" result="httpResponse">
<cfhttpparam name="To" type="url" value="myphone">
<cfhttpparam name="StartTime" type="url" value="2015-05-01">
<cfhttpparam name="EndTime" type="url" value="2015-06-01">
</cfhttp>
<cfdump var="#httpResponse#" label="httpResponse">
Also, https://www.twilio.com requires two SSL certificates. You need to import these to the keystore.
I going to implement the DucksBoard API. I made my custom counter on Ducksboard now I want to PUSH value. I read the tutorial I just found this line on DUCKSBOARD to push data
curl -v -u YOUR_API_KEY:unused -d '{"value": 10}' https://push.ducksboard.com/values/235
SO i try something like this in my Coldfusion code
<cfset var1 = '{"value":5}'>
<cfhttp url="https://push.ducksboard.com/values/xxxx" method="post" result="httpResp" timeout="60">
<cfhttpparam type="header" name="Content-Type" value="application/json" />
<cfhttpparam type="body" value="#serializeJSON(var1)#">
</cfhttp>
There is less information in the site of Duckboard.Can someone has implemented this.If yes then kindly tell me how to push value and where to use my API key?
I've not used Duckboard but it looks like what you have is correct. The CFHTTP tag takes 2 more parameters, username and password which you can fill in with your username and your API password like so:
<cfset var1 = '{"value":5}'>
<cfhttp url="https://push.ducksboard.com/values/xxxx" method="post"
result="httpResp" timeout="60" username="myusername" password="mypassword"
>
<cfhttpparam type="header" name="Content-Type" value="application/json" />
<cfhttpparam type="body" value="#serializeJSON(var1)#">
</cfhttp>
I study the API and found the solution You can use this code and change with yours this will work.And don't use serializeJSON in body tag.
<cfset var1 = '{"value":5}'>
<cfhttp url="https://push.ducksboard.com/v/xxxx" method="post" username="API-key" password="x" result="httpResp" >
<cfhttpparam type="header" name="Content-Type" value="application/json" />
<cfhttpparam type="body" value='#var1#'>
</cfhttp>
I'm running into issues trying to pass a cookie in my CFHTTP GET Statement.
Has anyone else experienced this? Pointers would be appreciated. BTW - I am using the x-http-method-override, because I saw this on a few other sites that were discussing this topic.
<cfhttp url="#this.apiServer#/api/v#this.version#/user.json"
method="POST" result="jorn">
<cfhttpparam type="COOKIE" name="ms_user" value="#arguments.patAppSession#" />
<cfhttpparam type="header" name="Content-Type" value="application/json" />
<cfhttpparam type="header" name="x-http-method-override" value="GET" />
<cfhttpparam type="body" value='#variables.dataFields#' />
</cfhttp>
<cfdump var = "#jorn#">
I am having troubles figuring out the google api.. I am trying to insert data into my fusion table via my coldfusion application..
<cfhttp url="https://www.google.com/accounts/ClientLogin" method="post" charset="utf-8">
<cfhttpparam type="formfield" name="accountType" value="GOOGLE"></cfhttpparam>
<cfhttpparam type="formfield" name="Email" value="MYUSERNAME"></cfhttpparam>
<cfhttpparam type="formfield" name="Passwd" value="MY PASSWORD"></cfhttpparam>
<cfhttpparam type="formfield" name="accountType" value="GOOGLE"></cfhttpparam>
<cfhttpparam type="formfield" name="service" value="fusiontables"></cfhttpparam>
</cfhttp>
this comes back with
SID=DQAAALoAAAC5eSJUrVB_WVchS1plunfW2YPUTadHAxoEbE0xMcOzQxeTloc2RWWBjoJi4jKm6NIiFbGbV_IQ3vuY9bl-Z0RS64OFAy5aUY-Do_nX8DpPhVkEyBzDScJidi73G7ZqWmkdykkIGCBrr7MLa-eBMrXZvLJP0D21xJTjxRWyeM4xuEMQGhEbnWwBL9RnEByr5Rsgzx7dl9n4tsYQOvaGV3ZcMlT0CooS2__orwC12UH7eKCk-REKzbX5Z-bbu4EdLps LSID=DQAAALwAAABV7lz-YRh02pR7IlWkKidScbYTQArBWnaAJpAlZQ9rgtgmdQCSBuIZQQ21QDXZLORwTAyDi-34Mjs8SKvI7ronBSuniDW2SGipYoUhZDEjxwR55DQc1AaI3JgGPMc69YGAVv-_EMwXlS7elWO6lDW-G4PTR6Aqa0DO3y7Iig-L7g2b7zMFq32JIvjUj5rofcykF27T8sOuhd0Z4XTvgO-18Kp2z8o6EK_5qjZcHPmih0GB6LeSElBo2wjah1TM2u0 Auth=DQAAALwAAADYQbciaOLab2Aw_QghTO8hR0DPDOjoWZVKeJ-ApGwoUz7OgcqVtSHMUvRHHZoKys5ygjhm2FiHSh1CvW1SicOvajwRZSstvghtsCQl-y7LeT8TMkeCj5ZIqy8A05wg1YjCz3F3eDz9TImtlvGij7IOdWJ3Ae4NE8WQdC0Js5Laccebhgjj7Lk9FkRgG9c3yRyGhu7LmsRbtLjfv5jwGoozDuCcx6b79bECoR8qABkT-e5HgF7sWjYbLfz667OCeA0
Now I am trying to insert into my table... I am passing the auth value from above.. I can not find anywhere in the google docs what the authentication fields should be.. any help would be greatly appreciated..
<cfhttp url="https://www.google.com/fusiontables/api/query" method="post" charset="utf-8">
<cfhttpparam type="formfield" name="sql" value="INSERT INTO 423555 (id, outcode,lat,lng) VALUES ('1','W14',1231232,-123123);"/>
<cfhttpparam type="header" name="Authorization" value="Auth"></cfhttpparam>
<cfhttpparam type="header" name="token" value="#listtoarray(cfhttp.FileContent,"=")[4]#"></cfhttpparam>
</cfhttp>
The AUTH should be the auth token you received in google's response.
From the docs you should make a header like:
Authorization: GoogleLogin auth=yourAuthToken
So, this would be
<cfhttpparam type="header" name="Authorization" value="GoogleLogin auth=#listtoarray(cfhttp.FileContent,"=")[4]#"></cfhttpparam>
This is assuming the #listtoarray(cfhttp.FileContent,"=")[4]# returns the value of the Auth property - I haven't counted it out to be sure.
I don't think, just glancing at the docs, the "token" header is needed.
But, #listtoarray(cfhttp.FileContent,"=")[4]# is a really fragile way of doing it. If Google were to reorder their response or change it, your code wouldn't work any more.
I would look to a more robust way of parsing the response. I would probably split the response on whitespace and turn it into a struct with the names as keys, then you could use something like
#response['auth']#