Trying to connect Datasift with API key using JAVA code


#1

Hi,
I have got trial license and tried to connect with Datasift API key for tumblr. But am not able to make a connection. Am getting an error. Please help me clearing the error.

Error:

Exception in thread "main" java.lang.NoClassDefFoundError: io/higgs/http/client/HttpRequestBuilder
    at com.datasift.client.DataSiftConfig.<init>(DataSiftConfig.java:34)
    at com.datasift.client.DataSiftConfig.<init>(DataSiftConfig.java:64)
    at ds.Tumblr.main(Tumblr.java:13)
Caused by: java.lang.ClassNotFoundException: io.higgs.http.client.HttpRequestBuilder
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 3 more

Program:

package ds;

import com.datasift.client.DataSiftClient;
import com.datasift.client.DataSiftConfig;
import com.datasift.client.core.Stream;
import com.datasift.client.stream.*;

public class Tumblr {
    public static void main(String... args) {
        
        // TODO: Enter your username and API key
          DataSiftConfig config = new DataSiftConfig("XXXXXXXX", "XXXXXXXXXXXXXXXXXXXXX");
        DataSiftClient datasift = new DataSiftClient(config);

        try {
            
            // Compile filter looking for mentions of brands
            String csdl = "interaction.content contains_any \"Calvin Klein, GQ, Adidas\"";
            Stream stream = datasift.compile(csdl).sync();
            
            datasift.liveStream().onError(new ErrorHandler()); // handles stream errors
             datasift.liveStream().subscribe(new Subscription(Stream.fromString("XXXXXXXXXXX")));
            datasift.liveStream().onStreamEvent(new DeleteHandler()); // handles data deletes

            // Subscribe to the stream
            datasift.liveStream().subscribe(new Subscription(stream));
            datasift.liveStream().unsubscribe(Stream.fromString("XXXXXXXXXXX"));
        } 
        catch(Exception ex)
        {
            // TODO: Your exception handling here
            System.out.println(ex);
        }                            
    }
    
    public static class Subscription extends StreamSubscription {
        public Subscription(Stream stream) {
            super(stream);
        }

        public void onDataSiftLogMessage(DataSiftMessage di) {
            System.out.println((di.isError() ? "Error" : di.isInfo() ? "Info" : "Warning") + ":\n" + di);
        }

        public void onMessage(Interaction i) {
            System.out.println("Tumblr:\n" + i);
        }
    }

    // Delete handler
    public static class DeleteHandler extends StreamEventListener {
        public void onDelete(DeletedInteraction di) {
            // You must delete the interaction to stay compliant
            System.out.println("DELETED:\n " + di);
        }
    }

    // Error handler
    public static class ErrorHandler extends ErrorListener {
        public void exceptionCaught(Throwable t) {
            t.printStackTrace();
            // TODO: do something useful..!
        }
    }
}

#2

It looks like your problem may be a missing dependency. The class HttpRequestBuilder is part of the HTTP client. it looks like you’re added the data-java.jar to your class path but not the dependencies of the library or at least not the HTTP client dependency.


#3

Thank you for the reply. Am getting the below error after clearing the previous error


Error

Exception in thread "main" java.lang.NoSuchMethodError: io.higgs.http.client.HttpRequestBuilder.isSupportedSSLProtocol(Ljava/lang/String;)Z
    at com.datasift.client.DataSiftConfig.<init>(DataSiftConfig.java:45)
    at com.datasift.client.DataSiftConfig.<init>(DataSiftConfig.java:64)
    at ds.Tumblr.main(Tumblr.java:13)

#4

It’s a little difficult to tell, but it appears that this may still be something to do with incompatible dependencies, and the version of the HTTP client you’re using being older than the one we require in the client.

Can you please confirm how you’re setting up your c;ass path? Is it using Maven / Gradle / manually / etc?
Also, where are you getting your dependencies from, and could you please provide a list of all the JARs added to your class path?

Just for your reference, we provide a full list of dependencies at https://github.com/datasift/datasift-java/blob/master/pom.xml#L48-L97, and the version of the HTTP client we are using is https://github.com/datasift/datasift-java/blob/master/pom.xml#L44