- Clone this repository
- Install dependencies
npm install
- You will need to your own MailChimp account (this is free to do). This is so that you can register a dummy application so that you have a client id and secret to use when testing:
- Instructions to register an app can be found here:
- https://mailchimp.com/developer/guides/access-user-data-with-oauth-2/#register-your-application
- When you get to
Redirect URI
field, you should inserthttp://127.0.0.1:3000/oauth/mailchimp/callback
as this is what is defined in the code we will use
- Instructions to register an app can be found here:
- Once you have registered a dummy app, copy the
client id
andclient secret
and paste it in the respectiveMAILCHIMP_CLIENT_ID
andMAILCHIMP_CLIENT_SECRET
variables in theindex.js
file - The code inside
index.js
is copied straight from Mailchimp's documentation - I have made a change in this code so that we are using
simple-oauth2
when retrieving the access token - you can find this onL89-95
. - To run the application, you just need to execute the following command in your terminal:
node index.js
- Then open up the web page, and click on the
here
link to go through MailChimp's login page to authorise the app (you use the same Mailchimp credentials to authorise)
- After authorisng the app, you should get re-directed back to your local webpage, with the access token displayed.
- You can re-create this by commenting out the simple oauth
getToken
logic i.e. comment outL90-94
, and then uncommentL69-85
and try re-running again.
- You can re-create this by commenting out the simple oauth
- I get the
Error: Unexpected token in JSON at position 0
error mentioned