The library can shorten or expand any link.
http://github.com/BR0kEN-/goo.gl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php **="" *="" @package="" googleurlshortener="" *="" @copyright="" propeople="" ukraine="" *="" @license="" mit,=""?><https: github.com/br0ken-/goo.gl/blob/master/license="">
* @version 0.1.9, May 5, 2014
* @link https://github.com/BR0kEN-/goo.gl
* @source https://github.com/BR0kEN-/goo.gl/blob/master/lib/GoogleURLShortener.php
* @author BR0kEN
*/
class GoogleURLShortener {
private
$request = 'https://www.googleapis.com/urlshortener/v1/url?',
$method,
$curl;
public function __construct($key = false) {
$this->curl = curl_init();
if ($key) {
$this->request .= "key=$key&";
}
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
return $this;
}
public function __destruct() {
if (curl_error($this->curl) !== '') {
curl_close($this->curl);
}
}
public function prepare($url) {
$this->method = strpos($url, '//goo.gl') !== false;
$method = $this->method ? 'expand' : 'shorten';
return $this->$method($url);
}
public function execute() {
$data = json_decode(curl_exec($this->curl));
if ($data->error) {
throw new \RuntimeException($data->error->message);
}
return $data ? ($this->method ? $data->longUrl : $data->id) : false;
}
protected function shorten($url) {
curl_setopt_array($this->curl, array(
CURLOPT_URL => $this->request,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode(array('longUrl' => $url)),
CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
CURLOPT_RETURNTRANSFER => true,
));
return $this;
}
protected function expand($url) {
curl_setopt_array($this->curl, array(
CURLOPT_URL => $this->request . http_build_query(array('shortUrl' => $url)),
CURLOPT_HTTPGET => true,
CURLOPT_RETURNTRANSFER => true,
));
return $this;
}
}
get a key - http://developers.google.com/url-shortener/v1/getting_started#APIKey
the call :
1
2
3
4
5
<?php require_once("googleurlshortener.php");="" $googl="new" googleurlshortener("your-key-here");="" $g="$googl-"?>prepare('https://pipiscrew.com/')->execute();
var_dump($g);
?>
get goo info, just merge .info in the end! js http://goo.gl/any.info
</broken></https:>
origin - http://www.pipiscrew.com/?p=2007 php-g00