我正在尝试回显访问令牌,并且它将变量设置为false而不是页面的值。这是为什么?
// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADERS => 'Content-Type: application/x-www-form-urlencoded',
CURLOPT_URL => 'https://accounts.google.com/o/oauth2/token',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
code => 'SUPER SECRET',
redirect_url=> 'http://example.com/wafds.php',
client_id=> 'SECRET,
client_secret=> 'SECRET',
grant_type=> 'authorization_code'
)
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
echo json_encode($resp);
答案 0 :(得分:0)
来自php.net/curl,curl_exec
成功时返回TRUE,失败时返回FALSE。你的curl返回false,因此你看到了错误。
答案 1 :(得分:0)
尝试使用SSL验证程序为false:
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_HTTPHEADERS => 'Content-Type: application/x-www-form-urlencoded',
CURLOPT_URL => 'https://accounts.google.com/o/oauth2/token',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
code => 'SUPER SECRET',
redirect_url=> 'http://example.com/wafds.php',
client_id=> 'SECRET,
client_secret=> 'SECRET',
grant_type=> 'authorization_code'
)
));