2015-10-05 103 views
2

我想在三個簡單的文本上使用雅虎內容分析。雅虎YQL文字大小限制

由於它的作品,但如果我增加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 

回答

0

我有同樣的問題。這樣長的字符串曾經工作過,所以在沒有能夠找到任何在線信息的情況下,爲什麼他們不再這樣做,我假定他們已經做了一個改變,限制了公共請求的字符串長度。可能由oauth驗證的請求的長度更長。

我沒有找到極限的弦變化。這可能是因爲你在之後正在清理文字,你正在計算字符數。例如,在對字符串進行清理之後,您將根據字符串中轉換的空間數量增加長度。

+0

啊,不,我錯了,我認爲這只是偶然,我是看到了串並沒有產生錯誤,它是如你所說,每串不同。也許這就是yahoo根據產生錯誤的字符串返回的數據量。在這種情況下,雅虎應用程序本身就是純粹的破壞(顯然,目前只有2人注意到了它) – user5449291