1. Go to this page and download the library: Download gabrielfs7/google-trends library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
gabrielfs7 / google-trends example snippets
use GSoares\GoogleTrends\Search\Psr7\Search;
use GSoares\GoogleTrends\Search\RelatedQueriesSearch;
use GuzzleHttp\Psr7\ServerRequest;
$search = new RelatedQueriesSearch();
// $search = new RelatedTopicsSearch();
// $search = new InterestOverTimeSearch();
// $search = new InterestByRegionSearch();
echo (string)(new Search($search))->search(ServerRequest::fromGlobals())->getBody();
$searchFilter = (new GSoares\GoogleTrends\Search\SearchFilter())
->withCategory(0) //All categories
->withSearchTerm('google')
->withLocation('US')
->withinInterval(
new DateTimeImmutable('now -7 days'),
new DateTimeImmutable('now')
)
->withLanguage('en-US')
->considerWebSearch()
# ->considerImageSearch() // Consider only image search
# ->considerNewsSearch() // Consider only news search
# ->considerYoutubeSearch() // Consider only youtube search
# ->considerGoogleShoppingSearch() // Consider only Google Shopping search
->withTopMetrics()
->withRisingMetrics();
$result = (new GSoares\GoogleTrends\Search\RelatedQueriesSearch())
->search($searchFilter)
->jsonSerialize();
$result = (new GSoares\GoogleTrends\Search\RelatedTopicsSearch())
->search($searchFilter)
->jsonSerialize();
$result = (new GSoares\GoogleTrends\Search\InterestOverTimeSearch())
->search($relatedSearchUrlBuilder)
->jsonSerialize();
$result = (new GSoares\GoogleTrends\Search\InterestByRegionSearch())
->search($relatedSearchUrlBuilder)
->jsonSerialize();