This quickstart uses an OAuth2 library which can be found here:
https://github.com/adoy/PHP-OAuth2
To install the library first download the archive: https://github.com/adoy/PHP-OAuth2/archive/master.zip. Unzip the contents into a directory that your PHP script can access.
Include the following files from the library in your script:
Create a client with your client id and secret (you can retrieve the id and secret in your nation from Settings > Developer > Register app):
Now use the client to generate the authorization url.
The above will output:
https://foobar.nationbuilder.com/oauth/authorize?response_type=code&client_id=yourClientId&redirect_uri=http%3A%2F%2Fwww.myapp.com%2Foauth_callback
Someone with access to the Nation's resources will have to visit that url in a browser, accept the application and retrieve the authorization code from the page url. That page url will look something like:
GET http://yourapp.example.com/oauth_callback?code=123456abcdef
Use the code to generate an access token:
The client is now ready to make resource requests
The above will output something like:
Array
(
[result] => Array
(
[page] => 1
[total_pages] => 1
[per_page] => 10
[total] => 9
[results] => Array
(
[0] => Array
(
[id] => 10
...
)
...
[8] => Array
(
[id] => 19
...
)
)
)
[code] => 200
[content_type] => application/json
)
