我已阅读此相关问题; 从 BitBucket 请求 OAuth 令牌
在上面的那个问题中,它使用 curl 。但是必须有一种方法可以使用gentero-api,因为它包含关于oauth 的php 类。
$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但是。我找不到任何好的资源。
编辑:
//我用这样的基本身份验证做到了。 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();
我想要做的是复制用户的身份验证并授予身份验证,就像这样。
$credss = $user->getcredenditals();
$issue->setCredentials( $credss ) ;
编辑:哇哇哇哇!!我从 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;
}