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):
- send in request header: authorization: bearer {access_token}
- include in (application/x-www-form-urlencoded) post body access_token={access_token}
- 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
Post a Comment