kirtusj/newsapi
Composer 安装命令:
composer create-project kirtusj/newsapi
包简介
A PHP Library for utilizing the NewsApi service
README 文档
README
A PHP Package for the NewsAPI utility
Installation
composer require kirtusj/newsapi
Usage
require __DIR__.'/vendor/autoload.php';
use kirtusj\newsapi\Scraper;
$newsapi = new Scraper($api_key="your_api_key_here");
everything
$all_articles = $newsapi->get_everything(array(
'q' => 'bitcoin',
'sources' => 'bbc-news,the-verge',
'domains' => 'bbc.co.uk,techcrunch.com',
'language' => 'en',
'sortBy' => 'relevancy',
'page' => 2));
top
$top_articles = $newsapi->get_top(array(
'q' => 'bitcoin',
'sources' => 'bbc-news, the-verge',
'category' => 'business',
'language' => 'en',
'country' => 'us'));
sources
$sources = $newsapi->get_sources(array());
The information held in these variables can be used however you like.
Example
input
$query = "Canada";
$page = 1;
$pageSize = 3;
$language = 'en';
$top_articles = $newsapi->get_top(array('q' => $query, 'page' => $page, 'pageSize' => $pageSize, 'language' => $language));
echo $top_articles;
output
{"status":"ok","totalResults":30,"articles":[{"source":{"id":"nhl-news","name":"NHL News"},"author":null,"title":"'Hockey Night in Canada': 5 Storylines","description":"The Boston Bruins and Toronto Maple Leafs will play for the fourth and final time during the regular season at Scotiabank Arena as part of a \"Hockey Night in Canada\" doubleheader on Saturday (7 p.m. ET; NHLN, CBC, SN1, CITY, NESN, NHL.TV). The home team has w…","url":"https://www.nhl.com/news/hockey-night-in-canada-5-storylines-january-12/c-303810292","urlToImage":"https://nhl.bamcontent.com/images/photos/303810922/1024x576/cut.jpg","publishedAt":"2019-01-13T00:56:28.3635098Z","content":"The Boston Bruins and Toronto Maple Leafs will play for the fourth and final time during the regular season at Scotiabank Arena as part of a \"Hockey Night in Canada\" doubleheader on Saturday (7 p.m. ET; NHLN, CBC, SN1, CITY, NESN, NHL.TV). The home team has w… [+4309 chars]"}]}
Endpoints
Endpoints return a JSON Object based on the input you give them
get_top
"top" : "https://newsapi.org/v2/top-headlines"
options
q, sources, language, country, pageSize, page
get_everything
"everything" : "https://newsapi.org/v2/everything"
options
q, sources, language, domains, excludeDomains, from, to, sort, pageSize, page
get_sources:
"sources" : "https://newsapi.org/v2/sources"
options
category, country, language
Input
countries:
'ae','ar','at','au','be','bg','br','ca','ch','cn','co','cu','cz','de','eg','fr','gb','gr','hk',
'hu','id','ie','il','in','it','jp','kr','lt','lv','ma','mx','my','ng','nl','no','nz','ph','pl',
'pt','ro','rs','ru','sa','se','sg','si','sk','th','tr','tw','ua','us','ve','za'
languages:
'ar','en','cn','de','es','fr','he','it','nl','no','pt','ru','sv','ud'
categories:
'business', 'entertainment', 'general', 'health', 'science', 'sports', 'technology'}
sortBy :
'relevancy','popularity','publishedAt'
to and from :
[from] date and [to] date Must be structured in YYYY-MM-DD format
Input types
"q" : string
"sources" : string
"language" : string
"country" : string
"pageSize" : int
"page" : int
"domains" : string
"date" : string
"sortBy" : string
"category" : str
kirtusj/newsapi 适用场景与选型建议
kirtusj/newsapi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 01 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「api」 「query」 「news」 「scrape」 「newsapi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kirtusj/newsapi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kirtusj/newsapi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kirtusj/newsapi 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
Query filtering in your frontend
Anax Database Active Record module for model classes.
A package to cast json fields, each sub-keys is castable
A PSR-7 compatible library for making CRUD API endpoints
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-01-11