我已阅读此相关的问题; 从到位桶请求的OAuth令牌
在上面这个问题,它使用卷曲。 但必须有办法用gentlero-API来做到这一点,因为它有PHP类,它了解OAuth。
$bb_user = 'myuser_name';
$bb_pass = 'mypasss';
$account_name = 'account_name';
$repo_slug = 'repo_name';
$issue = new issues();
$issue->setCredentials( new Basic($bb_user, $bb_pass) );
// iwanna do something like. but how??
// $issue->setCredentials( new Oauth($key, $secret) );
$issue->create($account_name, $repo_slug, array(
'title' => 'konu',
'content' => 'içerik metin 123123',
'kind' => 'proposal',
'priority' => 'blocker'
));
我想要做的OAuth的那样简单,但。 我coudnt找到任何好的种源。
编辑:
//我有这样的基本身份验证做到了。 https://github.com/gentlero/bitbucket-api/blob/master/docs/repositories/issues.md
//prepare
$issue = new Bitbucket\API\Repositories\Issues();
$issue->setCredentials( new Bitbucket\API\Authentication\Basic($bb_user, $bb_pass) );
//create new issue
$issue->create($account_name, $repo_slug, array(
'title' => 'dummy title',
'content' => 'dummy content',
'kind' => 'proposal',
'priority' => 'blocker'
));
而且有这个太; 这段代码的OAuth。
// OAuth 1-legged example
// You can create a new consumer at: account/user/<username or team>/api
$oauth_params = array(
'oauth_consumer_key' => 'aaa',
'oauth_consumer_secret' => 'bbb'
);
$user = new Bitbucket\API\User;
$user->getClient()->addListener(
new Bitbucket\API\Http\Listener\OAuthListener($oauth_params)
);
// now you can access protected endpoints as consumer owner
$response = $user->get();
我想要做的就是复制用户的身份验证,并给予AUTH发行,这样的事情。
$credss = $user->getcredenditals();
$issue->setCredentials( $credss ) ;
编辑:yahooooooooooo! 我学会了形式gazaret回答做什么。 这里是我的工作代码
public function createIssue()
{
$account_name = 'companyy';
$repo_slug = 'issuer';
$oauth_params = array(
'oauth_consumer_key' => 'key',
'oauth_consumer_secret' => 'secret'
);
$issue = new issues();
//this was the missing peace of the puzzle . one single line
$issue->getClient()->addListener( new OAuthListener($oauth_params) );
$issue->create($account_name, $repo_slug, array(
'title' => 'konu o_authlu',
'content' => 'içerik metin 123123',
'kind' => 'proposal',
'priority' => 'blocker'
));
return;
}