Solved

Coldfusion and YQL help

Posted on 2014-12-23
1
86 Views
Last Modified: 2015-01-27
Just trying to build a small stock widget for an intranet. I have coldfusion installed here. I'm trying to use YQL for this, if there is something easier let me know.

I enter in a basic query such as select * from yahoo.finance.stocks where symbol="yhoo"

The YQL console then generates a xml or json link. Should I use cfhttp? How would I show the output of this on an intranet page?

https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.stocks%20where%20symbol%3D%22yhoo%22&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
0
Comment
Question by:cb_it
1 Comment
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
Comment Utility
Yes, you need to use cfhttp and do a call to that url.  Looks like it returns XML by default. I'd suggest appending "&format=json" so you get back JSON instead. It's a bit simpler to work with than XML. Just use deserializeJSON(..) to convert the response string into CF arrays and structures.

<!--- Call url with "&format=json" to get back a JSON string --->
<cfset yourURL = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.stocks%20where%20symbol%3D%22yhoo%22&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys">
<cfhttp method="get" url="#yourURL#&format=json">

<!--- if successful --->
<cfif cfhttp.statuscode contains "200">
	<!--- deserialize JSON into CF structures and arrays --->
	<cfset response = deserializeJSON(cfhttp.fileContent)>
	<!--- for demo purposes, extract "results" key --->
	<cfset result = response.query.results>
	<cfdump var="#result#" label="Show response.query.results structure">
	
	<!--- do something with response --->
	<cfoutput>
		FullTimeEmployees #result.stock.FullTimeEmployees#<br>
		Industry #result.stock.Industry#<br>
		Sector #result.stock.Sector#<br>
		Start #result.stock.Start#<br>
		Sector #result.stock.Sector#<br>
		Symbol #result.stock.Symbol#<br>
	</cfoutput>
<cfelse>
    <!--- do something on error --->
	Error. Unable to retrieve url
	<cfdump var="#cfhttp#">
</cfif>

Open in new window

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now