?
Solved

Coldfusion and YQL help

Posted on 2014-12-23
1
Medium Priority
?
94 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 2000 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

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

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

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

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