我正在测试一个 cURL 函数来取回 Foursquare 上给定用户的访问令牌。以下函数以 json 格式将访问令牌打印到屏幕上
{"access_token":"5B25GW5LF3L4W04PALHK32X5Z3YGNUUVDHM2TFBQOWZSQ121"}
我在提取访问令牌的值时遇到问题。
这是我正在使用的功能:
函数 get_access_token($code){
$url = "https://foursquare.com/oauth2/access_token";
$fields = array(
'client_id' => urlencode($this->client_id),
'client_secret' => urlencode($this->client_secret),
'grant_type' => 'authorization_code',
'redirect_uri' => urlencode($this->redirect_url),
'code' => $code
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
return var_dump($result) /* prints bool(true) */;
}
如何将此访问令牌存储在变量中?
谢谢