25

I want to get valid link https://bitbucket.org/{username}/rss/feed?token={token} (this is main problem) and then get valid response from this link in CLI.

I know my required parameters, e.g. consumer_key, consumer_secret, request_token_url, authenticate_url, access_token_url.

I tried to use StudioIbizz\OAuth\OAuth1, but is seems to be designed for Browser, not for CLI.

I tried to run:

$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'];

and paste this $token to my RSS link, but then I see message You must have read access to access the RSS feed. from Bitbucket.

I need Step by Step instructions for serious dummies.


Edit: I tried this:

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

But then I get this:

Fatal error: Uncaught exception 'StudioIbizz\OAuth\OAuthException' with message 'Unexpected HTTP status #400'
123qwe
  • 1,525
  • 1
  • 14
  • 16
  • I couldn't find anything in Bitbucket docs about the token you should pass along the feed URL, but I'm sure the token given by the OAuth will not help you. I made some tries here and you need to be logged in even when giving a valid OAuth token. What kind of info you'd like to get from the feed? Maybe you can use specific API method to get that. – Gustavo Straube Sep 04 '15 at 20:20

3 Answers3

0

I don't see any function related with that on official documentation. Maybe that feature not exists. For more information, you could use this link:

https://confluence.atlassian.com/bitbucket/use-the-bitbucket-cloud-rest-apis-222724129.html

Julio Silva
  • 44
  • 1
  • 5
0

You could use stevenmaguire's Bitbucket OAuth 2.0 support for the PHP League's 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'];
cddoma
  • 48
  • 5
0

To get an RSS token for Bitbucket via PHP CLI, you will need to use the OAuth 1.0a protocol to authenticate your request. Here are the steps you can follow:

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);

Get the request token by calling the getTemporaryCredentials method and passing in the callback URL.

$temporaryCredentials = $client->getTemporaryCredentials();

Get the authorization URL by calling the getAuthorizationUrl method and passing in the temporary credentials.

$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);

Get the RSS token by calling the getRssToken method and passing in the token credentials

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

You can use this token to construct your RSS feed link:

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

Note that, this is just a general idea of how to use the OAuth library and it may vary depending on the library you are using. It's also important to check the documentation of that library for more details.