PHP Classes

PHP Short URL goo.gl API: Create short URLs and expand them using Google API

Recommend this page to a friend!
  Info   View files Example   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 123 This week: 1All time: 9,452 This week: 560Up
Version License PHP version Categories
googleurlapi 1.0.0MIT/X Consortium ...5HTTP, PHP 5, Web services
Description 

Author

This class can create short URLs and expand them using Google API.

It takes a given URL and sends a HTTP request to the Goo.gl Web server API to request a short version of the URL that is returned by the class as a string.

The class can also send a request the API to expand shorten a URL that was created previously.

Picture of Kevinralph M Tenorio
  Performance   Level  
Name: Kevinralph M Tenorio <contact>
Classes: 5 packages by
Country: Philippines Philippines
Age: 39
All time rank: 337325 in Philippines Philippines
Week rank: 411 Up4 in Philippines Philippines Up
Innovation award
Innovation award
Nominee: 3x

Example

<?php

   
/**
     * @param string $longUrl
     * @param string|null $api
     *
     * @return string|bool
     */
   
function googl_url($longUrl, $api = null)
    {
       
$api = $api ?? 'MY_GOOGLE_URL_SHORTER_API_KEY';
       
$instance = new GoogleURLAPI($api);

        if (
$response = $instance->shorten($longUrl)) {
            return isset(
$response['id']) ? $response['id'] : $longUrl;
        }
    }

   
$shorten = googl_url('https://my.domain.com/some-very-long-url/?url=is_very_long');

   
// Other Example Usage:

   
$googlurl = new GoogleURLAPI('MY_GOOGLE_URL_SHORTER_API_KEY');
   
$short = $googlurl->shorten('https://mylongdomain.com/long-url');
   
$long = $googlurl->expand($short['id']);
   
var_dump([$short, $long]);



  Files folder image Files  
File Role Description
Accessible without login Plain text file example.php Example Example usage
Plain text file GoogleURLAPI Class Simple Google URL Api Class

 Version Control Unique User Downloads Download Rankings  
 0%
Total:123
This week:1
All time:9,452
This week:560Up