nonsoniyi/the-guardian-api-client
最新稳定版本:v1.0.4
Composer 安装命令:
composer require nonsoniyi/the-guardian-api-client
包简介
PHP wrapper for the guardian APIs
关键字:
README 文档
README
PHP client library for the Guardian APIs. See documentation here. All available API modules are supported - Content, Tags, Sections, Editions, and Single Item.
Installation
You can install this package with composer using the command below
composer require nonsoniyi/the-guardian-api-client
Get API key
Sign up for an API key here
Making Requests
The primary Guardian\GuardianAPI class is a factory class that creates objects for each of the API modules, allowing you to make requests to any of them with your desired request parameters. You have to first create an object for it, then access your desired API module via the object. See the code snippets below:
$api = new Guardian\GuardianAPI(THE_GUARDIAN_API_KEY);
For Content:
$response = $api->content() ->setQuery("12 years a slave") ->setTag("film/film,tone/reviews") ->setFromDate(new DateTimeImmutable("01/01/2010")) ->setToDate(new \DateTimeImmutable()) ->setShowTags("contributor") ->setShowFields("starRating,headline,thumbnail,short-url") ->setOrderBy("relevance") ->fetch();
For Tags:
$response = $api->tags() ->setQuery("apple") ->setSection("technology") ->setShowReferences("all") ->fetch();
For Sections:
$response = $api->sections() ->setQuery("business") ->fetch();
For Editions:
$response = $api->editions() ->setQuery("uk") ->fetch();
For Single Item:
$response = $api->singleItem() ->setId("/sport/2022/oct/07/cricket-jos-buttler-primed-for-england-comeback-while-phil-salt-stays-focused") ->setShowStoryPackage(true) ->setShowEditorsPicks(true) ->setShowMostViewed(true) ->setShowRelated(true) ->fetch();
Community support
You can reach out to us on the Google Group here https://groups.google.com/g/guardian-api-talk for support
统计信息
- 总下载量: 1.14k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-03