php - Is it possible to return multiple properties in one call? - Stack Overflow

I want to return the title, first five sentences and the main image from a random wikipedia article.Is

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
Add a comment  | 

1 Answer 1

Reset to default 0

This 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);   

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745302013a4621490.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信