Google URL Shortener not working on App Engine PHP

Saturday, July 5, 2014

I am trying to short url with google api my site is hosted on google app engine so i cant use CURL have to use file_get_contents



$link = 'http://wwww.example.com';

$data = array('longUrl' => $link, 'key' => $apiKey);
$data = http_build_query($data);

$context = [
'http' => [
'method' => 'post',
'header'=>'Content-Type:application/json',
'content' => $data
]
];

$context = stream_context_create($context);
$result = file_get_contents('http://ift.tt/SaMcy4', false, $context);

$json = json_decode($result);
print_r($json);


Above code gives error



stdClass Object
(
[error] => stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[domain] => global
[reason] => parseError
[message] => Parse Error
)

)

[code] => 400
[message] => Parse Error
)

)


Please correct me where i am doing wrong :(







http://ift.tt/1vJhGgp