Showing posts with label google api. Show all posts
Showing posts with label google api. Show all posts

Tuesday, June 25, 2013

Google shorten URL - a Simple CURL script


    $url = "https://www.googleapis.com/urlshortener/v1/url";
    $strPost = '{"longUrl": "YOUR LONG URL"}';
 
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    //if your are using proxy url use proxy setting
    // curl_setopt($ch, CURLOPT_PROXY, $proxy);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_HTTPGET,1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/json")); //since i am requesting json response
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $strPost); // add POST fields
    curl_setopt($ch, CURLOPT_POST, 1);
    $result = curl_exec($ch);
    var_dump($result);
    curl_close($ch);
    exit;

If you dont want to use the google url shortner want to create your own


check it here :
http://opendummies.blogspot.in/2014/07/creating-url-shortner.html