tacman/bing-news-search

PHP Library for bing news search API.

2.0.5 2025-01-04 01:24 UTC

This package is auto-updated.

Last update: 2025-01-04 01:25:17 UTC


README

Fork of https://github.com/gabriel-yuji-inoue/BingNewsSearch

This fork drops support for PHP 7 and refactors how structures are populated. It is used by the survos/bing-news-bundle.

See more of this API at: https://docs.microsoft.com/en-us/bing/search-apis/bing-news-search

Dependencies

  • PHP 8.3+
  • GuzzleHttp 7.0.x >

Instalation

composer require tacman/bing-news-search

composer config repositories.bing_news '{"type": "vcs", "url": "git@github.com:tacman/BingNewsSearch.git"}' composer require tacman/bing-news-search:dev-refactor

composer config repositories.bing_news '{"type": "path", "url": "~/g/tacman/BingNewsSearch"}' composer require tacman/bing-news-search:*@dev

Usage of Api bing NEWS microsoft an easy way

Initialize the Client instance

$client = new Client(
  'apibingurl.com.br',  // https://api.bing.microsoft.com/
  'your_secret_key' // a1b2c3d4e5f6g7h8a1b2c3d4e5f6g7h8
);

Configure client

$client->enableExceptions(); // throw exceptions for debug
$client->disableSsl(); // disable Guzzle verification SSL

Search by category

// Ex: Search by business category, with pt_BR language, without safe search restriction;
$request = $client->category()
  ->get(Enum\Category::BUSINESS(), Enum\Language::PT_BR())
  ->setSafeSearch(Enum\SafeSearch::OFF())
  ->request();
$news = $request->getNews();

Search by key word

// Ex: Search by key word, limited at 50 items, with safe search restriction;
 $request = $client->search()
    ->get('something cool')
    ->setQuantity(50)
    ->setSafeSearch(Enum\SafeSearch::STRICT())
    ->request();
$news = $request->getNews();

Search by trending topics

// Ex: Get trending topics news, with en_US language.
 $request = $client->trending()
    ->get(Enum\Language::EN_US())
    ->request();
$news = $request->getTrending();

MORE

Check BingNewsSearch\Enum classes to know all avaiables search configurations, such as: Categories and SubCategories, Languages and more..