【问题标题】:2 legged oath request without command line没有命令行的 2 条腿誓言请求
【发布时间】:2012-12-23 11:53:33
【问题描述】:

我想用 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);

但问题是,我不想查询命令行.....我只想用我得到的 api 密钥进行 oauth 并直接使用我在输入 yql 时得到的命令的 url.. ..

像这样:

$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';

(我编辑了我想要的网址)。请不要问我为什么不使用命令来查询(长话短说)。我会很高兴得到一些帮助。 谢谢。

【问题讨论】:

  • 什么阻止了你?你试过什么?什么没有奏效?你做了哪些研究来解决这个问题?
  • 答:不确切知道如何发送 url 作为请求确实得到一个答案。我试过什么? A: 刚刚使用 javascript 获得了成功,但需要知道 php....什么没用?不知道具体如何尝试... 研究? A: yql 文档和google。但只是获取命令行示例。

标签: php oauth yql


【解决方案1】:

解决了:

http://code.google.com/p/oauth-php/wiki/ConsumerHowTo

include_once "oauth/library/OAuthStore.php"; include_once"oauth/library/OAuthRequester.php";

$key_1 = "你的钥匙"; $secret_1 = "你的秘密";

$ticks="%22AAPL%22%2C%22MSFT%22";

$options = array('consumer_key' => $key_1, 'consumer_secret' => $secret_1 ); OAuthStore::instance("2Leg", $options );

$url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20('$ticks')&format=json&diagnostics=true&env =store%3A%2F%2Fdatatables.org%2Falltableswithkeys"; // 这是请求的 URL $method = "GET"; // 你也可以使用 POST 改为 $params = null;

试试{ // 获取我们要发出的请求的请求对象 $request = new OAuthRequester($url, $method, $params); // 签署请求,执行 curl 请求并返回结果, // 出错时抛出 OAuthException2 异常 // $result 是一个数组形式:array ('code'=>int, 'headers'=>array(), 'body'=>string) $result = $request->doRequest();

    $response = $result['body'];
    $resp_array=json_decode($response,TRUE);
    echo $resp_array['query']['results']['quote'][1]['symbol']; // MSFT

} 捕获(OAuthException2 $e){ }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-04
    • 2010-12-02
    • 2012-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-22
    • 1970-01-01
    相关资源
    最近更新 更多