The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Java API: import com.constantcontact.ConstantContact cannot be resolved

Highlighted
Occasional Contributor

Java API: import com.constantcontact.ConstantContact cannot be resolved

Hi,

I'm trying to get started with the Java API.

I downloaded the Java SDK.

I installed the Eclipse Maven Plugin and imported the files using the Maven POM file.

 

All of the files in src/main/java appear to validate fine.

 

When I try to write the example given in the readme file it doesn't recognize the ConstantContact library, giving the error message: The import com.constantcontact.ConstantContact cannot be resolved.

 

I added a new package at the end of the packages in the src/main/java folder, after com.constantcontact.webhooks.model package.  From there I added a new class with the following code:

 

package JGL;

import com.constantcontact.components.Component;

import com.constantcontact.ConstantContact;

 

 

public class Run {

public static void main(String[] args){

ConstantContact constantContact = new ConstantContact("api", "token");

Contact contact = constantContact.getContact(2);

}

}

 

Note that Eclipse does recognise the components.Component library. 

 

Any ideas on why I can't get this to work?

 

Thanks!

Jon

 

2 REPLIES 2
Highlighted
Occasional Contributor

Re: Java API: import com.constantcontact.ConstantContact cannot be resolved

It occured to me that since the other library imports fine, maybe the sdk has changed since the original readme post.  I dug into the code and got this to work:

 

import com.constantcontact.components.contacts.Contact;

import com.constantcontact.exceptions.service.ConstantContactServiceException;

 

 

public class Run2 {

public static void main(String[] args){

String api = "api";

String token = "token";

 

ContactService cs = new ContactService(token,api);

 

Contact c = new Contact();

try{

c =cs.getContact("2");

}

catch(ConstantContactServiceException ccse) {

 

}

System.out.println(c.getFirstName());

 

Must be the that the original examples no longer work.

 

Thanks,

Jon

Highlighted
Honored Contributor

Re: Java API: import com.constantcontact.ConstantContact cannot be resolved

Hello,

 

My apologies for the delayed response! What you observed about changes in the SDK is correct! There was a major update to the SDK that was designed to move towards a proper service based SDK, rather than relying on a very large and difficult to read master class. The sample code included with the SDK on our github repo has also been updated and can be used as a reference if needed.

 

If you have any questions about using the updated SDK, please feel free to ask!

 

Sincerely,

Elijah G.
API Support Engineer
Developer Portal

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

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured