可以使用wikipedia api返回一个呼叫中的多个属性? 我想从随机的Wikipedia文章中返回标题,前五个句子和主要图像。 是否可以在一次通话中进行此操作? 我正在使用PHP。 第一个通话正常运行,并获得ti ...

问题描述 投票:0回答:1
首先通话正常,获得标题和前五个句子。 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

与其他参数发生冲突。
要解决此问题,您应该通过分开图像检索并正确提取属性来调整调用。这是第三个呼叫的改进版本:
php wikipedia mediawiki-api
1个回答
0
投票
this将在单个API调用中正确地将提取物(标题和前五句)和图像属性同时合并。关键是确保正确设置参数,并且您不会混合不相容的参数。


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.