Invalid token when submitting example add contact form

SOLVED
Highlighted
Occasional Contributor

Invalid token when submitting example add contact form

Hi I am just getting started implementing constant contact into a php site.  I am following the example code I found at: https://github.com/constantcontact/ctct_php_library

 

I was able to get the authetication to work but I get this error when submitting the add contact form:

HTTP Status 401 - Invalid token: [api key]

 

I did have to make this change to Authentication.php inside makeRequest(), otherwise I get undefined index exceptions.

if(!isset($accessInfo['key']))
    $accessInfo['key'] = $this->consumer->key;
if(!isset($accessInfo['secret']))
    $accessInfo['secret'] = $this->consumer->secret;	

 

I can't figure out how to get past this 401 error.  Can anybody give me any suggestions?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Occasional Contributor

Re: Invalid token when submitting example add contact form

Thanks for the suggestion.  I was able to get the access token after setting all the config URLs to the answer.php page. I added the username and access token to the config file and started creating the ConstantContact with the following code :

new ConstantContact ( "oauth2", $apikey, $username, $accessToken );


Now the add contact form is working for me!

View solution in original post

2 REPLIES 2
Highlighted
Employee

Re: Invalid token when submitting example add contact form

Hi,

 

You can use OAuth2 or basic authenticaion with the PHP wrapper currently (but we will be deprecating support for basic auth soon, so I would recommend using OAuth2).  The error you are getting seems to indicate you are using OAuth2 but haven't provided a valid access token.

 

You should be able to add the necessary credentials to the config.php file--have you provided the access token?  If you don't already have one, you can use the code and instructions here to generate an access token.  Sorry it's a lengthy process to generate one currently (we are working on improving that).

 

Also, it's worth mentioning that in the step before you get an access token, you get a code that you have to exchange for the token (not to be confused with the token itself).

 

Best Regards,

Shannon W.

API Support Specialist

Highlighted
Occasional Contributor

Re: Invalid token when submitting example add contact form

Thanks for the suggestion.  I was able to get the access token after setting all the config URLs to the answer.php page. I added the username and access token to the config file and started creating the ConstantContact with the following code :

new ConstantContact ( "oauth2", $apikey, $username, $accessToken );


Now the add contact form is working for me!

View solution in original post

Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Register for our "Making Sense of Online Marketing for Retail" Webinar

Join us on Thursday, August 13th at 2pm ET for a free webinar where we'll discuss how to incorporate online marketing into your retail store.

Read More
Featured