【发布时间】:2018-02-13 12:08:16
【问题描述】:
我正在尝试在PHP 中学习curl,我尝试实现具有以下身份验证语法的bitbucket API:
$ curl -X POST -u "client_id:secret" \
https://bitbucket.org/site/oauth2/access_token -d grant_type=password \
-d username={username} -d password={password}
这是根据文档:https://confluence.atlassian.com/bitbucket/oauth-on-bitbucket-cloud-238027431.html
在PHP 中使用时,我做了这样的事情:
$postData = array(
'grant_type' => 'password',
'username' => '*******',
'password' => '**********'
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://bitbucket.org/site/oauth2/access_token',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $postData,
));
$response = curl_exec($curl);
但是我遇到了一个错误
"{"error_description": "缺少客户端凭据;此请求需要使用 OAuth 客户端 ID 和密钥进行身份验证", "error": "unauthorized_client"}"
我也尝试过像这样使用 client_id 和 secret:
$postData = array(
'grant_type' => 'password',
'client_id' => '*******',
'secret' => '**********'
);
但仍然没有帮助。
【问题讨论】:
标签: php curl oauth bitbucket bitbucket-api