Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Contains classes and scripts that implement the Google APIs in very simple ways
PHP
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
google-feeds-api
google-qr
google-translate
google-url-shortner
nbproject
.gitattributes
.gitignore
README.md

README.md

GoogleAPI-Scripts

Contains classes and scripts that implement the Google APIs in very simple ways

Requirements

  • PHP 5.3
  • PHP GD (when working with QRCodeAPI and writing images)

Examples

Google QR Code API

    $qrobj = new GoogleApis\GoogleQrCodeAPI(150,'I am Lord Voldemort!');
    if($qrobj){
        echo $qrobj->getQrUrl();
        $qrobj->getPNG('voldemort_qr.png');
    }

Google URL Shortner API

Create your own API access key here: https://code.google.com/apis/console

Shorten a Link

    $long_url = 'https://github.com/emmanix2002/GoogleAPI-Scripts/tree/master/google-url-shortner';
    $api_key = 'your-google-api-access-key';
    $shortner_obj = new GoogleApis\GoogleUrlShortnerApi($long_url,$api_key);
    if($shortner_obj){
        echo $shortner_obj->shortenLink()
                        ->getShortLink();
        echo '<br />';
        echo $shortner_obj->getLink();
        var_dump($shortner_obj->getApiResponse());
    }

Expand a Link

    $api_key = 'your-google-api-access-key';
    $shortner_obj = new GoogleApis\GoogleUrlShortnerApi('',$api_key);
    if($shortner_obj){
        echo $shortner_obj->setShortLink('http://goo.gl/YD14V')
                            ->expandShortLink()
                            ->getLink();
        echo '<br />';
        echo $shortner_obj->getShortLink();
        var_dump($shortner_obj->getApiResponse());
    }

Google Translate API

This API is a paid service which you'll have to enable on your Google Console It makes it possible to translate strings or array of strings using the Google Translate API :-)

    $api_key = 'your-google-translate-api-key-goes-here';
    $translate_obj = new GoogleApis\GoogleTranslateApi($api_key);
    $text_1 = "My name is okeke emmanuel";
    $text_2 = array("My name is okeke emmanuel","Sunday Okpokor is my friend","I live in Lagos, Nigeria","I'm 5 years old!");
    if($translate_obj){
        $translations_1 = $translate_obj
                            ->translateText($text_1,GoogleApis\GoogleTranslateApi::LANG_FRENCH,GoogleApis\GoogleTranslateApi::LANG_ENGLISH)
                            ->getTranslations();
        var_dump($text_1);
        var_dump($translations_1);
        echo '<br />';
        echo $translate_obj->getApiResponseString();
        $translations_2 = $translate_obj
                            ->translateText($text_2,GoogleApis\GoogleTranslateApi::LANG_FRENCH,GoogleApis\GoogleTranslateApi::LANG_ENGLISH)
                            ->getTranslations();
        var_dump($text_2);
        var_dump($translations_2);
        echo '<br />';
        echo $translate_obj->getApiResponseString();
    }
Something went wrong with that request. Please try again.