Curl Json值不回显

Curl Json值不回显,curl,json,Curl,Json,我试图回显访问令牌,它将一个变量设置为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-T

我试图回显访问令牌,它将一个变量设置为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);
来自,curl_exec


成功时返回TRUE,失败时返回FALSE。您的curl返回false,因此您会看到false。

尝试将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'
    )
));

有什么原因导致它失败吗?再次从php.net中,string curl_error(资源$ch)-返回上次curl操作的错误消息。为什么不试着通过执行:print curl\u error($curl);client_id=>'SECRET,因此如果我使用它,我可以回显结果,但我得到{“error”:“invalid_grant”}。当我添加GoogleRequiredHeader应用程序类型时,错误消失了,但结果没有响应