我有这个curl代码来请求令牌(来自http://tutorialspage.com/simple-oauth2-example-using-php-curl/):
define("CALLBACK_URL","http://localhost/los/index");
define("AUTH_URL","https://accounts.google.com/o/oauth2/auth");
define("accESS_TOKEN_URL","https://oauth2.googleapis.com/token");
define("CLIENT_ID","**.apps.googleusercontent.com");
define("CLIENT_SECRET","**");
define("SCOPE","https://www.googleapis.com/auth/admin.directory.device.chromeos"); //
optional
function getToken(){
$curl = curl_init();
$params = array(
CURLOPT_URL =>
accESS_TOKEN_URL."?"."&grant_type=authorization_code"."&client_id=".
CLIENT_ID."&client_secret=". CLIENT_SECRET."&redirect_uri=". CALLBACK_URL,CURLOPT_RETURNTRANSFER => true,CURLOPT_MAXREDIRS => 10,CURLOPT_SSL_VERIFYPEER => false,CURLOPT_TIMEOUT => 30,CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,CURLOPT_CUSTOMREQUEST => "POST",CURLOPT_NOBODY => false,CURLOPT_HTTPHEADER => array(
"cache-control: no-cache","Content-Length: 0","content-type: application/x-www-form-urlencoded","accept: *","accept-encoding: gzip,deflate",),);
curl_setopt_array($curl,$params);
$response = curl_exec($curl);
$err = curl_error($curl);
echo $response;
curl_close($curl);
if ($err) {
echo "cURL Error #01: " . $err;
} else {
$response = json_decode($response,true);
if(array_key_exists("access_token",$response)) return $response;
if(array_key_exists("error",$response)) echo $response["error_description"];
echo "cURL Error #02: Something went wrong! Please contact admin.";
}
}
它给了我这个损坏的令牌:
��=�� � �;S4=;;8!�1M��w7\<��"V��#��;�& z^ꃗ_��X�ꜫ�[�hN� ��|�PD*M��� [
伴随此错误消息:
Warning: array_key_exists() expects parameter 2 to be array,null given in C:\wamp64\
是什么原因造成的?我在WAMP服务器3.0中运行了此程序