我编写了位API PHP代码
但不能扩大我的链接!
答复:expand
这是我的密码:
$api_key = '*******';
$link = $_POST['link'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.bitly.com/v3/expand?login=*******&apiKey=' . $api_key . '&shortUrl=' . $link . '');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$json = json_decode($response);
echo $json->data->expand->long_url;
发布于 2014-04-02 22:23:41
您的注释中包含的JSON无效。我已经把它修好了。将true传递给json_decode
函数,使其返回一个数组。
$json = json_decode($response, true);
{
"data": {
"expand": [
{
"global_hash": "900913",
"long_url": "google.com/",
"short_url": "bit.ly/ze6poY",
"user_hash": "ze6poY"
}
]
},
"status_code": 200,
"status_txt": "OK"
}
然后得到short_url
部分。
echo $json['data']['expand'][0]['short_url'];
您必须这样访问它,因为expand
是一个数组。
下面是一个使用JavaScript:http://jsfiddle.net/6ujGB/的演示
https://stackoverflow.com/questions/22829375
复制相似问题