Skip to main content

PHP Failing to work...

Very descriptive, I know. But after running through the PHP quickstart http://nationbuilder.com/api_documentation  I get so far as obtaining the code, but when trying to get an access token it returns a 400 bad request error with the message: "Your browser sent a request that this server could not understand."

This is all code provided by nationbuilder, so what went wrong? Is there anything I need to know before starting? I set up an app. It is set to public. It currently says "in review" for status but I see no mention of this mattering in the docs. 

This is the code:

require('src/OAuth2/Client.php');
require('src/OAuth2/GrantType/IGrantType.php');
require('src/OAuth2/GrantType/AuthorizationCode.php');


$client_id = 'xxxxxx'; //obviously i use the real id and key
$key = 'xxxxxx';

$client = new OAuth2\Client($client_id, $key);

$redirectUrl = 'http://www.some-site.com/oauth.php';

$authorizeUrl = 'https://xxx.nationbuilder.com/oauth/authorize';
/*

running this gives the code below.
$authUrl = $client->getAuthenticationUrl($authorizeUrl, $redirectUrl);

echo $authUrl;

*/
$code = 'xxxxxx';

$accessTokenUrl = 'https://xxx.nationbuilder.com/oauth/token';
$params = array('code' => $code, 'redirect_uri' => $redirectUrl);
$response = $client->getAccessToken($accessTokenUrl, 'authorization_code', $params);
$token = $response['result']['access_token'];
print_r($response);

 

Did I miss something? Or does someone have a more complete example to try?

Showing 3 reactions

How would you tag this suggestion?
Please check your e-mail for a link to activate your account.