最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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);   
发布评论

评论列表(0)

  1. 暂无评论