承接 gabrielfs7/google-trends 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gabrielfs7/google-trends

Composer 安装命令:

composer require gabrielfs7/google-trends

包简介

PHP Google Trends API

README 文档

README

Total Downloads Latest Stable Version

Branch master Build Status Scrutinizer Code Quality Code Coverage

A easier way to search on Google Trends and get a standard response in JSON or PHP DTO.

Dependencies

  • PHP 7.2+
  • PHP ext-json

Advantages on using this API

  • Get standard response that can be easily imported to your BI system.
  • No need to have a google account.
  • No need for web scraping data from Google Trends UI.
  • We deal with Google request token handling for you.
  • Allows you to create custom reports that better fit to your business.

Current support

  • PSR7 Support
  • Related topics Search.
  • Related queries Search.
  • Interest over time Search.
  • Interest by region Search.
  • Search by categories.
  • Search by location.
  • Language support.
  • Includes top or rising metrics.
  • Search type:
    • Web
    • Image
    • News
    • Youtube
    • Google Shopping

Usage

Using Open API and PSR7

The library provides PSR7 http message support. Check \GSoares\GoogleTrends\Search\Psr7\Search.

Example:

<?php
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();

You can check all Open API specs here.

Open_API_Specs

And you can view the open api using swagger editor with (File -> Import URL -> Select openapi.yaml URL).

Swagger_Editor_Instructions

If you prefer your own implementation, please use the steps bellow:

1) Create a SearchFilter with your restrictions

$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();

2) Execute the search you wish to

Related Queries

$result = (new GSoares\GoogleTrends\Search\RelatedQueriesSearch())
    ->search($searchFilter)
    ->jsonSerialize();

JSON response example:

{  
   "searchUrl":"http://www.google.com/trends/...",
   "totalResults":2,
   "results":[  
      {  
         "term":"hair salon",
         "value":100,
         "hasData": true,
         "searchUrl":"http://trends.google.com/...",
         "metricType":"TOP"
      },
      {  
         "term":"short hair",
         "value":85,
         "hasData": true,
         "searchUrl":"http://trends.google.com/...",
         "metricType":"RISING"
      }
   ]
}

Related Topics

$result = (new GSoares\GoogleTrends\Search\RelatedTopicsSearch())
    ->search($searchFilter)
    ->jsonSerialize();

JSON response example:

{  
   "searchUrl":"http://www.google.com/trends/...",
   "totalResults":2,
   "results":[  
      {  
         "term":"Google Search - Topic",
         "value":100,
         "hasData": true,
         "searchUrl":"http://trends.google.com/...",
         "metricType":"TOP"
      },
      {  
         "term":"Google - Technology company",
         "value":85,
         "hasData": true,
         "searchUrl":"http://trends.google.com/...",
         "metricType":"RISING"
      }
   ]
}

Interest Over Time

$result = (new GSoares\GoogleTrends\Search\InterestOverTimeSearch())
            ->search($relatedSearchUrlBuilder)
            ->jsonSerialize();

JSON response example:

{  
   "searchUrl":"http://www.google.com/trends/...",
   "totalResults":2,
   "results":[  
      {
            "interestAt": "2020-03-21T00:00:00+00:00",
            "values": [
              58
            ],
            "firstValue": 58,
            "hasData": true
      },
      {
        "interestAt": "2020-03-22T00:00:00+00:00",
        "values": [
          57
        ],
        "firstValue": 57,
        "hasData": true
      }
   ]
}

Interest By Region

$result = (new GSoares\GoogleTrends\Search\InterestByRegionSearch())
            ->search($relatedSearchUrlBuilder)
            ->jsonSerialize();

JSON response example:

{  
   "searchUrl":"http://www.google.com/trends/...",
   "totalResults":2,
   "results":[  
      {
        "geoCode": "US-RI",
        "geoName": "Rhode Island",
        "value": 100,
        "maxValueIndex": 0,
        "hasData": true
      },
      {
        "geoCode": "US-NY",
        "geoName": "New York",
        "value": 80,
        "maxValueIndex": 0,
        "hasData": true
      }
   ]
}

Installation

The Project is available on Packagist and you can install it using Composer:

composer require gabrielfs7/google-trends

Testing

Start PHP local server:

php -S localhost:8000 web/index.php

Access the api endpoints:

Example

After install it you can access an working example here.

Google Categories

You can find the categories available on Google here.

Contributing

I am really happy you can help with this project. If you are interest on how to contribute, please check this page.

gabrielfs7/google-trends 适用场景与选型建议

gabrielfs7/google-trends 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.25k 次下载、GitHub Stars 达 77, 最近一次更新时间为 2015 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 gabrielfs7/google-trends 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 gabrielfs7/google-trends 我们能提供哪些服务?
定制开发 / 二次开发

基于 gabrielfs7/google-trends 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.25k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 79
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 77
  • Watchers: 7
  • Forks: 31
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-04