google-image-search Get images by given query from "Google Image Search API JSON interface"

Google Image search (yii extension)

  1. Limitations by service
  2. 1. With given example
  3. 2. Write your own controller/view
  4. Screenshots

This extension use "Google Image Search API JSON interface" https://developers.google.com/image-search/v1/jsondevguide

Limitations by service

  • Max results per page: 8
  • Max pages: 8

This means you can not get more than 8 pages by one given query string. BUT you can change some of the url params and get different results.

One example is to change image type [png|jpg|gif|bmp] (but not search word) so you can get 4 times more results querying like this. Start with 8 pages of png, and continue with other types. In result you get 32 pages and every page with 8 results.

Requirements

  • cURL

Extension includes

  • GoogleImageSearch (CComponent) - it can be used alone with your code
  • ImageSearchController (CExtController) - Example of component use
  • views/search.php - html/js/css view for ImageSearchController (jQuery required)

How to use

You can use it in two ways.

  1. Based on given example
  2. Write your own controller/view

But both ways need same init configuration:

<?php
//..
'components'=>array(

    // Google image search component
     'imgSearch'=>array(
         'class'=>'application.extensions.googleImageSearch.GoogleImageSearch',
         //'cacheSec' => 3600, //default 1week
     ),

)
//..

1. With given example

For given example you need to add configuration to your controllerMap:

<?php
//..
'controllerMap'=>array(
    'imgSearch'=>array(
        'class'=>'application.extensions.googleImageSearch.controllers.ImageSearchController',
        //'layout' => '//layouts/layout', //default: layouts/main
    ),
),
//..

Now you can access example by adding /imgSearch/search to your base url (Result: http://my-domain.lc/imgSearch/search)

2. Write your own controller/view

You can use GoogleImageSearch component and use it where you want in you code. Here is a quick example:

<?php
        $imgSearch = Yii::app()->imgSearch;

        // All possible params:
        // https://developers.google.com/image-search/v1/jsondevguide#json_args
        $imgSearch->setParams(array(
            'rsz' => 4, //default: 8
            //'as_filetype' => 'png', //default to all types
        ));

        // OR set params one by one
        //$imgSearch->setParam('rsz',4);
        //$imgSearch->setParam('as_filetype','png');

        $jsonRaw = $imgSearch->getResults( $searchString );
        $json = json_decode( $jsonRaw );
        var_dump($json);

Available params

https://developers.google.com/image-search/v1/jsondevguide#json_args

About & More

Project at bitbucket: https://bitbucket.org/briiC/googleimagesearch.yii.ext

Screenshots

Search form Search results

3 0
8 followers
353 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Web Service
Tags: api, Google, search
Developed by: briiC.lv
Created on: Apr 8, 2013
Last updated: 11 years ago

Downloads

show all

Related Extensions