问题
in my search for a market data feed, I've been led to YQL for yahoo finance. It looks great, and very simple for the public use/ queries, but the daily limit for the public version is too small for my needs.. I got my yahoo ID to get started with oauth, but I can't find any good examples pertaining to what I'm trying to do...
I'd like to "sign in" with my desktop app in C#, and proceed to download data of interest. How do I use the oath dimension? My background as a point of reference is simple screen- scraping with the html agility pack, I've never had any experience with web services. Can anyone get me started. I'm stuck at the moment (and have been all week on this). Thanks in advance...
回答1:
In this case you are accessing public data (as opposed to user private data), so you'll be using OAuth two-legged authorization. This page on the YDN site is a good starting point for the different data types: Private Data v Public Data.
Two-legged means you need to sign your request a certain way (with your application key & secret), but there is no user-authorization step. OAuth signing is usually tricky, so most people will use an OAuth library.
There is a good walk-through on the YQL Code Examples page that illustrates this. Scroll down to the "Querying Public Data" section to see examples of calling YQL with a signed two-legged request.
<?php
include_once("yosdk/lib/Yahoo.inc");
define("API_KEY","your-api-key-here");
define("SHARED_SECRET","your-secret-here");
YahooLogger::setDebug(true);
$twoleg = new YahooApplication (API_KEY, SHARED_SECRET);
$query = "select * from yahoo.finance.historicaldata where symbol =\"YHOO\" and startDate = \"2011-12-01\" and endDate = \"2011-12-04\"";
$results = $twoleg->query ($query);
print_r ($results);
Running the above code gives some historical stock data like:
[quote] => Array
(
[0] => stdClass Object
(
[date] => 2011-12-02
[Date] => 2011-12-02
[Open] => 16.31
[High] => 16.41
[Low] => 16.03
[Close] => 16.05
[Volume] => 22714500
[Adj_Close] => 16.05
)
[1] => stdClass Object
(
[date] => 2011-12-01
[Date] => 2011-12-01
[Open] => 16.42
[High] => 16.46
[Low] => 16.09
[Close] => 16.23
[Volume] => 47059800
[Adj_Close] => 16.23
)
)
Of course you're asking about C#, but hopefully this gives you more background on what will be needed. I would search for two-legged OAuth solutions for C# - this question looks to have some working answers: Has anybody implemented 2 Legged OAuth using DNOA?.
Here's another possible solution, a web service that does the two-legged OAuth signing for you: OAuth-ify this: 2-legged OAuth service for YQL.
来源:https://stackoverflow.com/questions/8941569/how-do-i-get-started-with-oauth-for-yql-for-historical-stock-data