【问题标题】:Yahoo YQL text size limits雅虎 YQL 文本大小限制
【发布时间】:2026-01-24 22:30:02
【问题描述】:

我正在尝试对三个简单的文本使用 Yahoo Content Analysis。

因为它是有效的,但是如果我在 substr 命令中增加字符串长度,我会得到:

{"error":{"lang":"en-US","description":"Unknown error","status":"500"}}

谁能解释为什么会这样?根据文档,api 应该接受更大的字符串。

我也无法弄清楚为什么每个字符串的限制不同。有什么想法吗?

这是我的代码

<?php

/**
* Function to use Yahoo to analyse some simple text
* @param String $text
* @param String $format
* @return String $content
*/
function yahoo_content_analysis($text, $format = 'json')
{
    $url = "http://query.yahooapis.com/v1/public/yql";

    $query = 'SELECT * FROM contentanalysis.analyze WHERE text = "' . $text . '"';

    $characters = array(' ', '=', '"');
    $replacements = array('%20', '%3D', '%22');

    $query = str_replace($characters, $replacements, $query);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "q=$query&format=$format");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    $response = curl_exec($ch);
    $headers = curl_getinfo($ch);
    curl_close($ch);

    return $response;
}

// Text taken from wikipedia
$text1 = 'Computer programming (often shortened to programming or coding) is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs.';
$text2 = 'For the thousands of refugees and migrants landing on its beaches every day Greece Lesbos island is a step to safety and a brighter future in Europe';
$text3 = 'Hurricane Gert was a large tropical cyclone that caused extensive flooding throughout Central America and Mexico in September 1993. It originated over the southwestern Caribbean Sea and briefly attained tropical storm strength before crossing Nicaragua, Honduras, and the Yucatán Peninsula.';

// {"error":{"lang":"en-US","description":"Unknown error","status":"500"}}

$text1 = substr($text1, 0, 120);
echo $text1 . PHP_EOL;
$response1 = yahoo_content_analysis($text1);
echo $response1 . PHP_EOL; // json

echo PHP_EOL;    

$text2 = substr($text2, 0, 116);
echo $text2 . PHP_EOL;
$response2 = yahoo_content_analysis($text2);
echo $response2 . PHP_EOL; // json

echo PHP_EOL;

$text3 = substr($text3, 0, 124);
echo $text3 . PHP_EOL;
$response3 = yahoo_content_analysis($text3);
echo $response3 . PHP_EOL; // json

【问题讨论】:

    标签: php yahoo yql


    【解决方案1】:

    我也有同样的问题。如此长的字符串曾经可以工作,因此在无法在线找到任何关于他们不再这样做的信息的情况下,我认为他们已经进行了更改,限制了公共请求的字符串长度。可能是 oauth 认证的请求长度更长。

    我没有发现限制因字符串而异。这可能是因为您在计算字符数之后 对文本进行了清理。清理字符串后,您正在增加长度,例如,根据转换的字符串中有多少空格。

    【讨论】:

    • 啊不,我错了,我认为我看到的字符串没有产生错误只是偶然,正如你所说,每个字符串都不同。也许是雅虎根据产生错误的字符串返回的数据量。在这种情况下,雅虎应用程序本身就被彻底破坏了(显然,目前只有 2 人注意到它)