cancel
Showing results for 
Search instead for 
Did you mean: 

Username doesn't exist?

Occasional Participant

Username doesn't exist?

I'm having trouble getting past Step 1 of setting up the API. 

    session_start();
    include_once('constantcontact/ConstantContact.php');
    $username = 'veaney';
    $apiKey = 'MYAPI';
    $consumerSecret = 'MYSKEY';
    $Datastore = new CTCTDataStore();
    $DatastoreUser = $Datastore->lookupUser($username);
    if($DatastoreUser){
	$ConstantContact = new ConstantContact('oauth2', $apiKey, $DatastoreUser['username'], $consumerSecret);
	$ContactLists = $ConstantContact->getLists();
	var_dump($ContactLists);
    }

 Yields OAuth Exception: Username veaney not found in datastore

 

Whereas this

    session_start();
    include_once('constantcontact/ConstantContact.php');
    $username = 'veaney';
    $apiKey = 'MYAPI';
    $consumerSecret = 'MYSKEY';
    $ConstantContact = new ConstantContact('oauth2', $apiKey, $username, $consumerSecret);
    $ContactLists = $ConstantContact->getLists();
    var_dump($ContactLists);

 Yields HTTP Status 401 - Invalid token: {shows my secret key}

 

I'm at a total loss of what to do here. The API/Secret keys are exactly what I have. Am I entering the wrong user name, perhaps? Is it supposed to be something other than what is used to log in to the account?

 

4 REPLIES 4
Occasional Participant

Re: Username doesn't exist?

Alright, I've gotten around this initial issue. Now I have an actual access token, however, it's not working.

 

When using the example from the PHP wrapper Wiki

$ConstantContact = new ConstantContact('oauth2', $apiKey, $username, $consumerSecret);

It doesn't work.

 

So instead I tried

$ConstantContact = new ConstantContact('oauth2', $apiKey, $username, $accessToken);

Which still gets me an invalid access token error. 

 

So, basically, I'm not sure how to get oauth2 to work with the PHP wrapper. I did manage to get it working by playing around with the method here, but I was kind of hoping for a more plug and play solution. Is there a trick to getting the wrapper to work, perhaps?

 

Just wanted to edit because what I thought was the access token wasn't. I'm not really sure what it was, actually...

CTCT Employee

Re: Username doesn't exist?

Hi,

 

You probably got the authorization code, which needs to be exchanged for the access token in a final call to our servers.  The authorization code is only good for 10 seconds though, so you will have to go through the OAuth2 proces again.  I have a step by step example on this page.  If that isn't what you were using to begin with, I'd recommend following all of the steps in it to see if you can successfully generate your access token.  

 

You could also just look at the final call made in that example, since it sounds like you were very close.  The step you were missing looks something like this:

 

POST https://oauth2.constantcontact.com/oauth2/oauth/token? grant_type=authorization_code
&client_id=<your_API_KEY>
&client_secret=<your_client_secret>
&code=<unique_code>
&redirect_uri=your_redirect_URI>

 

 

Best Regards,

Shannon W.

API Support Specialist

Occasional Participant

Re: Username doesn't exist?

Hi Shannon!

 

Yes, I finally went through that and got the full access token. I had been using the auth code before, and just missing that last step.

 

I'm trying really hard to wade through the PHP wrapper, and just not having much luck. I keep getting authorization issues when trying to schedule campaigns. The end goal here is to have automated generation and scheduling of campaigns via my site. I'm doing OK creating the campaign, but when I attempt to schedule it I receive this error.

 

Constant Contact HTTP Request Exception:
HTTP Status 403 - Not Allowed to access customer

type Status report

message Not Allowed to access customer

description Access to the specified resource (Not Allowed to access customer) has been forbidden.

JBoss Web/2.1.1.SNAPSHOT

Here's some of the code I'm using to generate [presently dummy] campaigns - most of it was copy/pasted from the example in the PHP wrapper.

 

	// Create campaign in Constant Contact Account, first verified address as from and reply-to
	$NewCampaign = $ConstantContact->addCampaign($Campaign, $VerifiedAddresses['addresses'][0], $VerifiedAddresses['addresses'][0]);
	if($NewCampaign) {
	    $time = gmdate("Y-m-d\TH:i:s\Z", strtotime('+15 minutes'));
	    var_dump($time);
	    $ConstantContact->scheduleCampaign($NewCampaign, $time);
	}

 This is the date that is output: 2013-01-31T19:14:34Z

 

CTCT Employee

Re: Username doesn't exist?

Hi,

 

You do need special permission for your API Key to schedule an email campaign (see the second paragraph of this page), which is likely why you're getting the 403 error.

 

Please email us at webservices@constantcontact.com with your username and API Key so that we can give you the required permissions.

 

Best Regards,

Shannon W.

API Support Specialist