Syncing database with google fusion table - coldfusion

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']#

Related

ColdFusion CFHTTPPARAM Content-Type?

I am attempting to upload a file to the dropbox api using cfhttp. I am getting an error from Dropbox stating the Content-Type is incorrect:
Bad HTTP "Content-Type" header:
"application/octet-stream,multipart/form-data;
boundary=-----------------------------7d0d117230764". Expecting one of
"application/octet-stream", "text/plain; charset=dropbox-cors-hack".
It appears to me that ColdFusion is appending multipart.form-data to the content type I defined in the cfhttpparam header. I am not sure how to prevent this. I am using the code below:
<cfhttp method="post" url="https://content.dropboxapi.com/2/files/upload" result="uploadFile" multipart="no">
<cfhttpparam type="header" name="Authorization" value="Bearer #DropboxAccessToken#">
<cfhttpparam type="header" name="Dropbox-API-Arg" value="#serializeJSON(stFields)#">
<cfhttpparam type="header" name="Dropbox-API-Select-User" value="#DropboxMemberID#">
<cfhttpparam type="header" name="Content-Type" value="application/octet-stream">
<cfhttpparam type="file" name="1_1036.gif" file="C:\1_1036.gif">
</cfhttp>
Any ideas on what could be going on?
The "multipart/form-data" is probably added automatically because type="file" is used. If the API is expecting content type "application/octet-stream", that suggests it expects file data to be uploaded through the http request body, rather than as a named "file" field. Instead of type="file" try using:
<cfhttpparam type="body" value="#FileReadBinary('C:\1_1036.gif')#">

Windows Push Notification Services Token request via ColdFusion

I am trying to get the "access token" from WNS via a ColdFusion request but I get a "Bad Request" response. I believe I have everything set up correctly following the instructions here. My devices are registering the URI's to my backend.
Here is a simple code snippet;
(I've hidden the secret key of course)
<cfhttp url="https://login.live.com/accesstoken.srf" method="post" result="httpResp">
<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded" />
<cfhttpparam type="URL" name="grant_type" value="client_credentials" />
<cfhttpparam type="URL" name="client_id" value="ms%2Dapp%3A%2F%2Fs%2D1%2D15%2D2%2D1197233413%2D3602308102%2D1084427847%2D2188608249%2D1036687727%2D3580410356%2D2392468796" />
<cfhttpparam type="URL" name="client_secret" value="************************" />
<cfhttpparam type="URL" name="scope" value="notify.windows.com" />
I am also getting failed response when I test the URL directly via the browser. Appreciate your help.
Thank you,
Ian.
I think your cfhttpparam fields now set to "URL" should actually be set to "FORMFIELD" based on the example on MSDN.
<cfhttpparam type="FORMFIELD" name="grant_type" value="client_credentials" />
<cfhttpparam type="FORMFIELD" name="client_id" value="..." />
<cfhttpparam type="FORMFIELD" name="client_secret" value="************************" />
<cfhttpparam type="FORMFIELD" name="scope" value="notify.windows.com" />
The example appears to put thes in the content area (showing a raw post) - so these are form fields of a post, not URL fields right?

Twilio Rest API Filtering using Coldfusion11

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.

Credly API get SDK builder temp_token using ColdFusion

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.

Push value to DucksBoard in ColdFusion

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>