php - Get email from bitbucket -


i need implement bitbucket authorization on symfony2 project. i`m using hwioauthbundle , guzzle forming request. emails need json response https://bitbucket.org/api/1.0/users/{accountname}/emails every time

client error response [url] https://bitbucket.org/api/1.0/users/{accountname}/emails [status code] 401 [reason phrase] unauthorized"

but i`m authorized @ bitbucket . here code:

$url = 'https://bitbucket.org/api/1.0/users/'.$response->getusername().'/emails';     $client = new client();     $request = $client->createrequest('get', $url);     $emails = $client->send($request); 

it seems not providing access token when making requests, therefore bitbucket rejecting them 401.

from docs:

once have access token, per rfc-6750, can use in request in of following ways (listed least desirable):

  1. send in request header: authorization: bearer {access_token}
  2. include in (application/x-www-form-urlencoded) post body access_token={access_token}
  3. put in query string of non-post: ?access_token={access_token}

i first lookup docs of oauth library using , find out how user's access token specific service (bitbucket in case). then, include in request headers in guzzle:

$client = new client();  $request = $client->createrequest(     'get',     'https://bitbucket.org/api/1.0/users/' . $response->getusername() . '/emails',     [         'authorization' => 'bearer ' . $useroauthaccesstoken,     ] );  $emails = $client->send($request); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -