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

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

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

jonasva/google-trends

Composer 安装命令:

composer require jonasva/google-trends

包简介

Unofficial Google Trends PHP API

README 文档

README

This unofficial API provides an easy way to query Google Trends for certain data. The data can be returned as decoded JSON, GoogleTrendsTerm objects or as a formatted array (only suited for making your own graph). CSV exports or iFrame results are not supported.

Keep in mind that this is an unofficial API. Whether or not it continues to work depends on Google. Use at your own risk.

Installation

To get the latest version of this package require it in your composer.json file.

"jonasva/google-trends": "dev-master"

Run composer update jonasva/google-trends to install it.

Usage

The API works with a session object, which requires you to authenticate with a valid Google account. This is necessary as unauthenticated users will hit the trends quota limit after just a couple of requests, resulting in a 1-day ban.

First init a session object with your google account credentials. You'll need to have a recovery email setup in your Google account (https://support.google.com/accounts/answer/183726?hl=en), in case you are asked to verify yourself. Pass that recovery email to the session object like below:

    $config = [
        'email'         =>  'my.google.account@gmail.com',
        'password'      =>  'mygooglepassword',
        'recovery-email'  =>  'other.email.address@example.com',
    ];

    $session = (new GoogleSession($config))->authenticate();

Then create a request and add some parameters. The example below returns an array of a trend line chart's labels (date) and data points for terms 'cycling' and 'golf'.

    $response = (new GoogleTrendsRequest($session)) // create request
                    ->addTerm('cycling') // add a term to compare
                    ->addTerm('golf') // add a term to compare
                    ->setDateRange(new \DateTime('2014-02-01'), new \DateTime()) // date range
                    ->getGraph() // cid (linechart)
                    ->send(); //execute the request

    $data = $response->getFormattedData(); // return formatted data suitable for creating a line chart

Examples

Fetch the top google search queries in Belgium between February 2014 and now. It's equivalent to this data on Google trends: https://www.google.com/trends/explore#geo=BE&date=2%2F2014%2015m&cmpt=q&tz=

    $response = (new GoogleTrendsRequest($session))
                    ->setDateRange(new \DateTime('2014-02-01'), new \DateTime()) // date range, if not passed, the past year will be used by default
                    ->setLocation('BE') // For location Belgium
                    ->getTopQueries() // cid (top queries)
                    ->send(); //execute the request

    $data = $response->getTermsObjects(); // return an array of GoogleTrendsTerm objects

Fetch the rising queries related to 'cycling' and in category 'Arts & Entertainment' (category id 0-3) for the past year.

    $response = (new GoogleTrendsRequest($session))
                    ->addTerm('cycling') // term cycling
                    ->setCategory('0-3') // category id for arts & entertainment
                    ->getRisingQueries() // cid (rising queries)
                    ->send(); //execute the request

    $data = $response->getTermsObjects(); // return an array of GoogleTrendsTerm objects

Remarks

The getTermsObjects() method cannot be used for a response obtained with the getGraph() method.

    $response->getTermsObjects();

To get a response's raw contents, the following method can be used:

    $response->getResponseContent();

To just json decode response content, you can use this method:

    $response->jsonDecode();

Each request has a random delay between 0.1 and 1.5 seconds. This setting can changed in the GoogleSession object.

    $session->setMaxSleepInterval(0); // disable the delay
    $session->setMaxSleepInterval(300); // set the max delay to 3 seconds

To check if you are authenticated, you can use the checkAuth() method on a GoogleSession instance.

    $response->checkAuth(); // return bool

Some other options are available as well, check the code for more information.

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

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

它主要适用于以下技术方向: 「api」 「google」 「trends」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 384
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 22
  • 点击次数: 17
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 22
  • Watchers: 5
  • Forks: 15
  • 开发语言: PHP

其他信息

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