的SoundCloud(的oauth2)API获得访问令牌失败
我想基础上的SoundCloud登录授权在我的网站的用户。
I'm trying to authorize users on my site based on a Soundcloud login.
它使用OAuth认证。
It uses Oauth authentication.
在用户点击我的网站上一个按钮,被重定向到的SoundCloud网站,它的记录。
The user has to click a button on my site and is redirected to the Soundcloud site, where it logs in.
在用户重定向回到我的网站,我要得到的accessToken。
After that the user get redirected back to my site where I have to get an accessToken.
这失败消息:请求的URL回应HTTP code 0
我甩了卷曲的东西,如果你需要它:
I've dumped the curl stuff if you need it:
[data]; False
[info][url] : https://api.soundcloud.com/oauth2/token
[content_type] ; NULL
[http_code] : 0
[header_size] : 0
[request_size] : 0
[filetime] : -1
[ssl_verify_result] : 0
[redirect_count] : 0
[total_time] : 0.031
[namelookup_time] : 0
[connect_time] : 0.031
[pretransfer_time] : 0
[size_upload] : 0
[size_download] : 0
[speed_download] : 0
[speed_upload] : 0
[download_content_length]: -1
[upload_content_length] : -1
[starttransfer_time] : 0
[redirect_time] : 0
[certinfo] []
在code我执行:
The code I execute:
$soundcloud = new SoundcloudModel('*****', '*****', '*****');
try {
$accessToken = $soundcloud->accessToken($this->request['code']);
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
exit($e->getMessage());
}
在的SoundCloud API code:
The Soundcloud API code:
protected function _getAccessToken($postData, $curlOptions = array())
{
$options = array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postData);
$options += $curlOptions;
$response = json_decode(
$this->_request($this->getAccessTokenUrl(), $options),
true
);
if (array_key_exists('access_token', $response)) {
$this->_accessToken = $response['access_token'];
return $response;
} else {
return false;
}
}
protected function _request($url, $curlOptions = array())
{
$ch = curl_init($url);
$options = $this->_curlOptions;
$options += $curlOptions;
if (array_key_exists(self::CURLOPT_OAUTH_TOKEN, $options)) {
$includeAccessToken = $options[self::CURLOPT_OAUTH_TOKEN];
unset($options[self::CURLOPT_OAUTH_TOKEN]);
} else {
$includeAccessToken = true;
}
if (array_key_exists(CURLOPT_HTTPHEADER, $options)) {
$options[CURLOPT_HTTPHEADER] = array_merge(
$this->_buildDefaultHeaders(),
$curlOptions[CURLOPT_HTTPHEADER]
);
} else {
$options[CURLOPT_HTTPHEADER] = $this->_buildDefaultHeaders(
$includeAccessToken
);
}
curl_setopt_array($ch, $options);
$data = curl_exec($ch);
$info = curl_getinfo($ch);
print_r(array('ch'=>$ch, 'data'=>$data, 'info'=>$info));
curl_close($ch);
$this->_lastHttpResponseHeaders = $this->_parseHttpHeaders(
substr($data, 0, $info['header_size'])
);
$this->_lastHttpResponseBody = substr($data, $info['header_size']);
$this->_lastHttpResponseCode = $info['http_code'];
if ($this->_validResponseCode($this->_lastHttpResponseCode)) {
return $this->_lastHttpResponseBody;
} else {
throw new Services_Soundcloud_Invalid_Http_Response_Code_Exception(
null,
0,
$this->_lastHttpResponseBody,
$this->_lastHttpResponseCode
);
}
}
对不起,这个长的帖子,希望你们能帮助我了!
Sorry for this long post, hope you guys can help me out!
明白了。
我发现,通过使用PHP卷曲使用了过时的证书捆绑(至少在Windows上)。
I found out that cURL used by PHP uses an outdated cert bundle (at least on Windows).
我从下载了最新的证书捆绑文档/ caextract.html
并增加了以下卷曲选项:
I've downloaded the latest cert bundle from: http://curl.haxx.se/docs/caextract.html and added the following cURL option:
curl_setopt($ch, CURLOPT_CAINFO, 'C:/absolute/path/to/cacert.pem');