Solved

Coldfusion and YQL help

Posted on 2014-12-23
1
91 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 40515402
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

738 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