【问题标题】:YQL query service replacement now that Yahoo shut it down雅虎关闭后,YQL 查询服务替换
【发布时间】:2019-01-04 22:10:02
【问题描述】:

现在雅虎关闭了query.yahooapis.com,如下消息所示,有人知道免费更换吗?

“重要停产通知:自 2019 年 1 月 3 日星期四起,YQL 服务 在 query.yahooapis.com 将被淘汰。这将影响用户 datatables.org 以及使用它创建功能的开发人员 YQL 服务。要继续使用我们免费的 Yahoo Weather API,请使用 https://weather-ydn-yql.media.yahoo.com/forecastrss 作为你的新 API 端点。联系 yahoo-weather-ydn-api@oath.com 获取凭据 加入这个免费的 Yahoo Weather API 服务。其他基于 YQL 使用 query.yahooapis.com 的服务将不再运行。”

需要替换 "//query.yahooapis.com/v1/public/yql?q=" 才能让我的 rss 刮板工作。

function yql(a, b) {
        return (
          "**//query.yahooapis.com/v1/public/yql?q=**" +
          encodeURIComponent(
            "select * from " +
              b +
              ' where url="' +
              a +
              '" limit ' +
              params.feedcount
          ) +
          "&format=json"
        );
      }

【问题讨论】:

  • 我的小应用程序也受此影响,显然整个 YQL 的东西都将停止服务。

标签: json rss yql


【解决方案1】:

我发现了这个,它对我很有用。 https://api.rss2json.com 有一个免费层,它比 YQL 更直接,用于 RSS 到 JSONP 的转换。

【讨论】:

    【解决方案2】:

    我构建了CloudQuery,它能够将大多数网站转换为 API,并且它有一个简单易用的 Web 界面来创建 API。并且在github上开源

    【讨论】:

    • 网站给出这个错误:"Internal server error"
    【解决方案3】:

    这里有一个可能的解决方案。

    a) 您需要某种代理来允许使用 ajax 从不同来源加载内容。建议将 CORS 标头等列入白名单并添加,以防止利用您的代理。例如,使用此功能在您的一台服务器上创建一个 php 文件:

    $valid_url_regex = '/.*(rss|feed|atom).*/';
    $url = $_GET['url'];
    if ( !preg_match( $valid_url_regex, $url ) ) exit;
    
    $feeds = file_get_contents($url);
    //this is some workaround to get special namespaces into the json
    $feeds = str_replace("<content:encoded>","<contentEncoded>",$feeds);
    $feeds = str_replace("</content:encoded>","</contentEncoded>",$feeds);
    $feeds = str_replace("<media:content ","<mediaContent ",$feeds);
    $feeds = str_replace("</media:content>","</mediaContent>",$feeds);
    
    $simpleXml = simplexml_load_string($feeds, "SimpleXMLElement", LIBXML_NOCDATA);//this is for CDATA
    $json = json_encode($simpleXml);
    header("Access-Control-Allow-Origin: http://yourdomainnamehere");
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Max-Age: 86400'); 
    print $json;
    

    b) 对代理脚本执行异步 ajax 调用并处理数据:

    function loadRss(url)
    {
        $.ajax({
            url: 'yourserverurl/rssproxy.php?url='+url,
            type: 'GET',          
            success: function(response) {
                handleResponse(JSON.parse(response));
            }
        });
    }
    
    
    function handleResponse(response) { 
        var entries; 
    
        if(response.entry) //ATOM
            entries = response.entry;
        else if(response.channel.item) //RSS 1/2
            entries = response.channel.item;
    
        var feedTitle="";
    
        if(response.title)
            feedTitle = response.title;
        else if(response.channel.title)
            feedTitle = response.channel.title;
    
        //iterate all news entries
        $.each(entries, function (i, e) {
                console.log("Entry #"+i);
                console.log(e);
                //access the data as necessary like e.content, e.summary, e.contentEncoded etc....
        }
        );
    
    }
    

    几年前我将我的 google rss api 更改为 YQL,现在我不得不再次这样做,花了几个小时,但这次你不会依赖某些 3rd-party 供应商,希望你可以使用你的新阅读器代码,直到 rss 因著名的过滤气泡而优先于人类消失;)

    以上代码只是一个提示,当然,如果您想将响应映射到通用 YQL 结构,您将不得不投入一些时间。我没有这样做,而是根据需要访问了响应的属性。

    【讨论】:

    • 感谢您的帮助,我会看看是否可以实施您的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-27
    • 2023-03-15
    • 2018-02-18
    • 2011-01-02
    • 1970-01-01
    相关资源
    最近更新 更多