什么是数据类型(获取请求)bit.ly oauth2

时间:2013-10-13 15:33:39

标签: php html json curl

{ "status_code": 200, "status_txt": "OK", "data": { "long_url": "http:\/\/google.com\/", "url": "http:\/\/bit.ly\/17A2GVj", "hash": "17A2GVj", "global_hash": "3j4ir4", "new_hash": 0 } } 

我做完

之后得到类似的东西
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => 'https://api-ssl.bitly.com/v3/shorten?access_token=xxx&longUrl=http%3A%2F%2Fgoogle.com%2F',
    CURLOPT_USERAGENT => 'Mozilla/4.0'
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);

echo $resp;

我如何阅读“哈希”

1 个答案:

答案 0 :(得分:2)

$respObj = json_decode($resp);
echo $respObj->data->hash;
默认情况下,

json_decode会返回stdClass的实例。访问stdClass'成员->