Rizaldy
Blog Universitas Komputer Indonesia

Google Shortener

ngeliat seo blog unikom bagus, pengen ngetes bloging ah wkkw.
 
Ini skrip buat bikin shortener url, akses via cli. klo pengen dikembangin silahkan, gue mah males wkwk. Dibuat pake bahasa php (oop biar kaya orang2).
 
<?php
error_reporting(0); //Think by ur self ;-p
/**
* Simple Google Shortener Script
* @Usage: php script_name.php url | ex: php short.php google.com
* @description Get API KEY from : http://code.google.com/apis/console/
* @author fariz rizaldy <farizrizaldy@outlook.co.id>
* @url https://github.com/farizdev/proje/shortener.php
*/
class short{
function __construct($api){
global $argv;
$this->api=$api;
$this->link=$argv[1];
$this->short($this->link);
}
function short($link){
$proses = array('longUrl' => $link, 'key' => $this->api);
$json = json_encode($proses);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url?key='.$this->api);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$exec = curl_exec($ch);
$jsonexec = json_decode($exec);
curl_close($ch);
$cek = $jsonexec->id == TRUE ? "Hasil: ".$jsonexec->id."
" : "Maaf URL yang kamu input tidak valid!
";
echo $cek;
}
}
$pendekin = new short('YOUR_API_KEY'); #API key bisa didapet dari: http://code.google.com/apis/console/ 
?>
 
semoga bemanfaat
Format Lainnya : PDF | Google Docs | English Version
Diposting pada : Sabtu, 05 Desember 15 - 20:59 WIB
Dalam Kategori : GOOGLE, SHRTENER
Dibaca sebanyak : 1785 Kali
Tidak ada komentar pada blog ini...
Anda harus Login terlebih dahulu untuk mengirim komentar
Facebook Feedback