我想用php制作一个2腿的oauth yql请求。 到目前为止:
// Include the PHP SDK.
include_once("yosdk/lib/Yahoo.inc");
// Define constants to store your API Key (Consumer Key) and
// Shared Secret (Consumer Secret).
define("API_KEY","her_comes the key");
define("SHARED_SECRET","here_comes_the_secret");
$two_legged_app = new YahooApplication(API_KEY,SHARED_SECRET);
$stock_query = "elect * from ......";
$stockResponse = $two_legged_app->query($stock_query);
var_dump($stockrResponse);
但问题是,我不想查询命令行.....我只想用oi键我得到并直接使用url我得到的命令当我输入yql .. ..
像这样:$url='http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20('+url_stocks+')&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys';
(我编辑了我希望的网址。)请不要问为什么我不使用命令查询(长篇故事)。得到一些帮助我会很高兴。 谢谢。
答案 0 :(得分:0)
解决了它:
http://code.google.com/p/oauth-php/wiki/ConsumerHowTo
include_once" oauth / library / OAuthStore.php&#34 ;; include_once"的OAuth /库/ OAuthRequester.php&#34 ;;
$ key_1 =" your_key&#34 ;; $ secret_1 =" your_secret&#34 ;;
$蜱="%22AAPL%22%2C%22MSFT%22&#34 ;;
$ options = array(' consumer_key' => $ key_1,' consumer_secret' => $ secret_1); OAuthStore :: instance(" 2Leg",$ options);
$ url = " HTTP://query.yahooapis.com/v1/public/yql Q =选择%20 *%20from%20yahoo.finance.quotes%20where%20symbol%20英寸20%(' $蜱&# 39;)及格式= JSON&安培;诊断=真安培; ENV =商店%3A%2F%2Fdatatables.org%2Falltableswithkeys&#34 ;; //这是请求的网址$ method =" GET&#34 ;; //你也可以用 而不是$ params = null;
尝试{ //获取我们想要的请求的请求对象 $ request = new OAuthRequester($ url,$ method,$ params); //签署请求,执行curl请求并返回结果, //在错误上抛出OAuthException2异常 // $ result是一个表单数组:array(' code' => int,' headers' => array(),' body' = >字符串) $ result = $ request-> doRequest();
$response = $result['body']; $resp_array=json_decode($response,TRUE); echo $resp_array['query']['results']['quote'][1]['symbol']; // MSFT
} catch(OAuthException2 $ e){}