PHP 中的雅虎财经 CSV API 和 appid

发布于 2024-12-22 18:40:29 字数 574 浏览 1 评论 0原文

我有一个小应用程序从 Yahoo! 检索股票数据在我的本地服务器上工作正常。当我将其上传到远程服务器时,它停止返回数据并在 FF 中显示安全错误:“此网站不提供所有权信息。”

然后我意识到我必须申请一个应用程序 ID,但问题仍然存在:

$appid = urlencode('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx--'); // My App ID
...
$cHandle = curl_init();
curl_setopt($cHandle, CURLOPT_URL, 'http://download.finance.yahoo.com/d/quotes.csv?appid='.$appid.'&s='.$symbol.'&f='.$properties.'&e=.csv');
curl_setopt($cHandle, CURLOPT_RETURNTRANSFER, true);
$dataStr = curl_exec($cHandle);
curl_close($cHandle);
echo json_encode($dataStr);

知道我的代码出了什么问题吗?提前致谢

I've a small application retrieving stock data from Yahoo! working fine in my local server. When I uploaded it to a remote server it stopped returning data and showing a security error in FF: "This web site does not supply ownership information."

Then I realized I must apply for an application ID wich I did but still the problem remains:

$appid = urlencode('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx--'); // My App ID
...
$cHandle = curl_init();
curl_setopt($cHandle, CURLOPT_URL, 'http://download.finance.yahoo.com/d/quotes.csv?appid='.$appid.'&s='.$symbol.'&f='.$properties.'&e=.csv');
curl_setopt($cHandle, CURLOPT_RETURNTRANSFER, true);
$dataStr = curl_exec($cHandle);
curl_close($cHandle);
echo json_encode($dataStr);

Any idea what's wrong in my code? Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿咻 2024-12-29 18:40:29

您的错误与您的代码无关 - Firefox 中的错误与 SSL 证书有关。至于为什么你的代码不起作用 - 在 CURL 周围添加一些错误检查,看看会产生什么:

$appid = urlencode('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx--'); // My App ID
...
$cHandle = curl_init();
curl_setopt($cHandle, CURLOPT_URL, 'http://download.finance.yahoo.com/d/quotes.csv?appid='.$appid.'&s='.$symbol.'&f='.$properties.'&e=.csv');
curl_setopt($cHandle, CURLOPT_RETURNTRANSFER, true);
...

if(curl_exec($cHandle) === false)
{
    echo 'Curl error: ' . curl_error($cHandle);
}
else
{
    echo 'Operation completed without any errors';
}

// Close handle
curl_close($ch);

Your error is not connected with your code - the Error in Firefox is related to the SSL certificate. As to why your code is not working - add some error checking around the CURL and see what that produces :

$appid = urlencode('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx--'); // My App ID
...
$cHandle = curl_init();
curl_setopt($cHandle, CURLOPT_URL, 'http://download.finance.yahoo.com/d/quotes.csv?appid='.$appid.'&s='.$symbol.'&f='.$properties.'&e=.csv');
curl_setopt($cHandle, CURLOPT_RETURNTRANSFER, true);
...

if(curl_exec($cHandle) === false)
{
    echo 'Curl error: ' . curl_error($cHandle);
}
else
{
    echo 'Operation completed without any errors';
}

// Close handle
curl_close($ch);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文