我正在編寫下面的代碼來獲取授權令牌。curl到google時invalid_request響應
指定授權的代碼變量
$code = $this->request->query['code'];
我已刪除了我的客戶的祕密張貼問題。
$clientSecret = "";
初始化捲曲
$ch = curl_init();
$header[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode("code=".$code."&
client_id=289710071999.apps.googleusercontent.com&
client_secret=".$clientSecret."&
redirect_uri=http://budzzflorist.localhost.com/users/google&
grant_type=authorization_code"));
curl_setopt($ch, CURLOPT_URL, "https://accounts.google.com/o/oauth2/token");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$request_result = curl_exec($ch);
print_r(curl_getinfo($ch));
echo "\n\ncURL error number:" .curl_errno($ch); // print error info
echo "\n\ncURL error:" . curl_error($ch);
var_dump(json_decode($request_result,true));
看起來您正在使用CakePHP。你應該看看['HttpSocket'](http://api.cakephp.org/class/http-socket)類。 – 2012-07-27 17:30:38
我有這個選擇,但我想用捲曲來做。 – user1558329 2012-07-27 17:36:04