如何通过PHP CLI获取BitBucket的RSS令牌?

pdtvr36n  于 2023-01-29  发布在  PHP
关注(0)|答案(3)|浏览(109)

我想获取有效链接https://bitbucket.org/{username}/rss/feed?token={token}(这是主要问题),然后在CLI中从该链接获取有效响应。
我知道所需的参数,例如consumer_key, consumer_secret, request_token_url, authenticate_url, access_token_url
我试着使用StudioIbizz\OAuth\OAuth1,但它似乎是为浏览器设计的,而不是为CLI设计的。
我试着逃跑:

$this->OAuth = new \StudioIbizz\OAuth\OAuth1($this->consumer_key,$this->consumer_secret);

$requestToken = $this->OAuth->getRequestToken($this->request_token_url,$this->authenticate_url);

$token = $requestToken['oauth_token_secret'];

然后把这个$token粘贴到我的RSS链接上,但是我看到了来自Bitbucket的消息You must have read access to access the RSS feed.
我需要一步一步的指示严重的傻瓜。
编辑:我试过这个:

$accessToken = $this->OAuth->getAccessToken($this->access_token_url,$requestToken['oauth_token_secret'],$requestToken['oauth_token']);

但我得到了这个:

Fatal error: Uncaught exception 'StudioIbizz\OAuth\OAuthException' with message 'Unexpected HTTP status #400'
vc6uscn9

vc6uscn91#

我在官方文档中没有看到任何与此相关的功能。可能该功能不存在。要了解更多信息,您可以使用此链接:
https://confluence.atlassian.com/bitbucket/use-the-bitbucket-cloud-rest-apis-222724129.html

lndjwyie

lndjwyie2#

您可以将stevenmaguire的Bitbucket OAuth 2.0 support用于PHP联盟的OAuth 2.0 Client

$provider = new Stevenmaguire\OAuth2\Client\Provider\Bitbucket([
    'clientId'          => '{bitbucket-client-id}',
    'clientSecret'      => '{bitbucket-client-secret}',
    'redirectUri'       => 'https://example.com/callback-url'
]);

$token = $_GET['code'];
djp7away

djp7away3#

要通过PHP CLI获取Bitbucket的RSS令牌,您需要使用OAuth 1.0a协议来验证您的请求。以下是您可以遵循的步骤:

Install an OAuth library for PHP that can be used in CLI, such as the league/oauth1-client package.

Create a new instance of the OAuth client by passing in your consumer key and consumer secret.
$client = new League\OAuth1\Client\Server\Bitbucket($consumerKey, $consumerSecret);

通过调用getTemporaryCredentials方法并传入回调URL来获取请求令牌。

$temporaryCredentials = $client->getTemporaryCredentials();

通过调用getAuthorizationUrl方法并传入临时凭据来获取授权URL。

$authorizationUrl = $client->getAuthorizationUrl($temporaryCredentials);
Use this URL to authenticate the request via the browser.
After successful authentication, you will get a verifier code.
Get the access token by calling the getTokenCredentials method and passing in the temporary credentials and the verifier code.
$tokenCredentials = $client->getTokenCredentials($temporaryCredentials, $verifier);

$tokenCredentials = $client->getTokenCredentials($temporaryCredentials, $verifier);

通过调用getRssToken方法并传入令牌凭据来获取RSS令牌

$rssToken = $client->getRssToken($tokenCredentials);

您可以使用此标记构造RSS提要链接:

https://bitbucket.org/{username}/rss/feed?token={$rssToken}

请注意,这只是如何使用OAuth库的一般概念,它可能会因您使用的库而异。查看该库的文档以了解更多详细信息也很重要。

相关问题