admin管理员组文章数量:1420181
I want to return the title, first five sentences and the main image from a random wikipedia article.
Is it possible to do this in a single call?
I'm using PHP.
First call works fine and gets the title and first five sentences.
Second call works and gets the images.
Third call is my attempt to combine the first two calls and it returns the images but throws a message:
["warnings"] => array(1) { ["main"] => array(1) { ["*"] => string(67) "Unrecognized parameters: explaintext, exsectionformat, exsentences."
First ...
$url='.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='.php?action=query&prop=pageimages&pithumbsize=200&format=json&pageids='.$item->id;
$x=json_decode(file_get_contents($url), true);
dump($x);
Third...
$url='.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);
I want to return the title, first five sentences and the main image from a random wikipedia article.
Is it possible to do this in a single call?
I'm using PHP.
First call works fine and gets the title and first five sentences.
Second call works and gets the images.
Third call is my attempt to combine the first two calls and it returns the images but throws a message:
["warnings"] => array(1) { ["main"] => array(1) { ["*"] => string(67) "Unrecognized parameters: explaintext, exsectionformat, exsentences."
First ...
$url='https://en.wikipedia./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./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./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);
Share
Improve this question
edited Jan 29 at 14:41
DarkBee
15.5k8 gold badges72 silver badges118 bronze badges
asked Jan 29 at 11:25
user1106252user1106252
917 bronze badges
1 Answer
Reset to default 0This is the url I used to get the info I needed. The key, I think, is the chaining of '&prop=extracts|pageimages|info' in the request.
$url='https://en.wikipedia./w/api.php?action=query&format=json&prop=extracts|pageimages|info&inprop=url&exintro=1&explaintext=1&exsentences=5&piprop=original&pageids=' . $item->id;
$x=json_decode(file_get_contents($url), true);
dump($x);
本文标签: phpIs it possible to return multiple properties in one callStack Overflow
版权声明:本文标题:php - Is it possible to return multiple properties in one call? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745302012a2652425.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论