public function getAccessToken($code = null)
{
if (!$code) {
if (!isset($_GET['code'])) {
throw new Exception('could not retrieve code out of callback request and no code given');
}
$code = $_GET['code'];
}
$parameters = array('grant_type' => 'authorization_code', 'type' => 'web_server', 'client_id' => $this->_client->getClientKey(), 'client_secret' => $this->_client->getClientSecret(), 'redirect_uri' => $this->_client->getCallbackUrl(), 'code' => $code);
if ($this->_scope) {
$parameters['scope'] = $this->_scope;
}
$http = new HttpClient($this->_configuration->getAccessTokenEndpoint(), 'POST', http_build_query($parameters));
//$http->setDebug(true);
$http->execute();
$this->_parseAccessTokenResponse($http);
}