Google Trend API codeigniter php
This is a basic libary enable you to read/save google trends keywords as a JSON once a day. If JSON appear, read it. If not, curl the keyword and save as a JSON for next request. This library is used with the curl.
Package CodeIgniter / PHP
Subpackage Libraries
Author kelvin Kwong Ho
Version 0.1
Date 9/1/2013
For some moments, my site needs a content or keyword for dynamic run or request. Like the site of http://zonmine.com, call google trend once a day to gather the hot keyword in shopping (for 30 days and 7 days ). Then it uses the Gtrend keyword to search products in Amazon. The content will appear updating daily and easily go up to 2000-5000 products in few days.
Get the google trend keywod and save as a JSON
- PHP 5.1+ with curl which I used a Curl library ( https://github.com/philsturgeon/codeigniter-curl ) .
- CodeIgniter
$response = $this->create_trend_keyword( ); //return json ["ipod","tv","camera","xbox","sony","speakers","nikon","xbox 360","headphones","ipod touch"]
-
Put the Gtrend.php under codeigniter "application/libraries" and make sure you have the Curl.php or $this->curl funtion
-
Loading the libraries by either one of the following way:
a. Autoload 'config/Autoload.php' add a param in $autoload['libraries'] = array('Curl', 'Gtrend');
b.function __construct() {
parent::__construct();
$this->load->library('Gtrend');
}
c.$this->load->library('Gtrend');
-
setup the JSON file data path : $config['data_base_path'] = 'www/data/';
-
Call the library as follow :
$result = $this->create_trend_keyword( ); //default is cat "0-18-78" => Shopping > Consumer Electronics, type TOP $result = $this->create_trend_keyword( $category, $type );
- The keyword JSON is now stored as {data_base_path}/{Ymd_type_cat_}.json
e.g. 20130901_TOP_0-18-78_.json
Content :
["ipod","tv","camera","xbox","sony","speakers","nikon","xbox 360","headphones","ipod touch"]
https://github.com/kelvin2go/GoogleTrend/
The data is from
http://www.google.com/trends/fetchComponent
You will have chance to reach your limit for curling google trends.
If you have any questions or found any bugs, please message or pull request me.