我正在尝试使用 google api 缩短 url 我的网站托管在 google app 引擎上,所以我不能使用CURL必须使用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('https://www.googleapis.com/urlshortener/v1/url', false, $context);
$json = json_decode($result);
print_r($json);
上面的代码给出了错误
stdClass Object
(
[error] => stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[domain] => global
[reason] => parseError
[message] => Parse Error
)
)
[code] => 400
[message] => Parse Error
)
)
请纠正我做错的地方:(