0

I am using the bitbucket api and there I am getting an access token when I enter the following url: 'https://bitbucket.org/site/oauth2/authorize?client_id={client_id}&response_type=code' and it redirects me to https://api.bitbucket.org/2.0/repositories/{my-team}/?code={code} And I need to get that {code} from the redirect url I do it with curl the following way:

public function getCode()
{
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, "https://bitbucket.org/site/oauth2/authorize?client_id=".config('app.bitbucket_key')."&response_type=code");

    $result = curl_exec($ch);

    if (curl_errno($ch)) {
        return 'Error: invalid credentials';
    }

    return $result;
}

but as a result I get true. I want to get the code query parameter in the redirect url. How can I do this

EDIT:

When I check with curl_getinfo() I see that it redirects me to another url which is: https://bitbucket.org/account/signin/?next=/site/oauth2/authorize%3Fclient_id%3D{my_client_id}%26response_type%3Dcode

u_mulder
  • 54,101
  • 5
  • 48
  • 64
Angel Miladinov
  • 1,596
  • 4
  • 20
  • 43

1 Answers1

0

I don't know anything about the related api but to get a html response from curl you need to set return transfer option.

    curl_setopt($ch,  CURLOPT_RETURNTRANSFER, true); 
kylngr
  • 61
  • 8