0

我正在尝试回显访问令牌,并将变量设置为 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);
4

2 回答 2

0

php.net/curl, curl_exec

成功时返回 TRUE,失败时返回 FALSE。您的卷曲返回错误,因此您看到错误。

于 2013-09-21T05:00:07.380 回答
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'
    )
));
于 2013-09-21T05:33:21.187 回答