【问题标题】:Facing error while getting currency exchange rate from Google Finance API从 Google Finance API 获取货币汇率时遇到错误
【发布时间】:2018-03-20 02:06:49
【问题描述】:

以下代码在过去几个月的生产环境中运行良好。 最近它开始坏了。

昨天它给出了file_get_contents 函数的 HTTP 错误问题。 今天,在执行时它显示 Undefined Offset 错误。

我不确定 Finance Google API 发生了什么变化。

public function getJPYtoUSDExchangeRate(){
        $from    = 'JPY';
        $to    = 'USD';
        $amount  = 1;
        $data = file_get_contents("https://finance.google.com/finance/converter?a=$amount&from=$from&to=$to");
        preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted);
        $converted = preg_replace("/[^0-9.]/", "", $converted[1][0]);
        return number_format(round($converted, 3),2);
}

【问题讨论】:

标签: currency-exchange-rates


【解决方案1】:

最后,我通过更新的谷歌网址找到了解决方案,用于货币转换器 https://finance.google.com/bctzjpnsun/converter

谢谢

【讨论】:

    【解决方案2】:

    问题出在链接上,google最近更新了api链接,我对现有链接检查10次发现成功。 尝试更改此链接 https://www.google.com/finance/converter

    看到这个 https://www.techbuy.in/google-finance-api-currency-converter-not-working-updated-link-check-currency-converter/

    【讨论】:

    猜你喜欢
    • 2012-01-04
    • 1970-01-01
    • 2011-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多