首先通话正常,获得标题和前五个句子。 second呼叫有效并获取图像。 第三次呼叫是我尝试结合前两个呼叫的尝试,并返回图像,但传达了一条消息:
[“警告”] => array(1){ [“ main”] => array(1){ [“*”] => string(67)”未识别的参数:Dixplaintext,ExectionFormat,ExSentences。”
First ...
$url='https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exsentences=5&explaintext=&exsectionformat=plain&format=json&pageids='.$item->id;
$x=json_decode(file_get_contents($url), true); ```
dump($x);
Second...
$url='https://en.wikipedia.org/w/api.php?action=query&prop=pageimages&pithumbsize=200&format=json&pageids='.$item->id;
$x=json_decode(file_get_contents($url), true);
dump($x);
Third...
$url='https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exsentences=5&explaintext=&exsectionformat=plain&format=json&prop=pageimages&pithumbsize=200&pageids='.$item->id;
$x=json_decode(file_get_contents($url), true); ```
dump($x);
您遇到的问题是由于第三个呼叫中参数的不正确组合所致。 Wikipedia API返回错误,因为一起使用时某些参数不兼容。具体来说,
exsentences
,
explaintext
和
exsectionformat
与其他参数发生冲突。要解决此问题,您应该通过分开图像检索并正确提取属性来调整调用。这是第三个呼叫的改进版本:
$url = 'https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exsentences=5&explaintext=true&format=json&pageids=' . $item->id . '&prop=pageimages&pithumbsize=200';
$x = json_decode(file_get_contents($url), true);
dump($x);
this将在单个API调用中正确地将提取物(标题和前五句)和图像属性同时合并。关键是确保正确设置参数,并且您不会混合不相容的参数。