-->

Alchemy API, getting started with Java

2019-05-26 01:34发布

问题:

I've recently started a new project that requires the use of AlchemyAPI to analyze information on websites. I've started coding in Java and I use Eclipse, but I am relatively new and I am just really lost on how to actually use the API. So far, I've downloaded the Java SDK, and installed it according to what it says on GitHub. Now this is where I am stuck. How do I actually use the API? Do I have to import something? If yes, what/how exactly?

There are examples in the form of ".jar" files in the "dist" folder but I can only execute them using "java -jar", so they do not seem to be that useful in actually learning how to call or use the API in my code.

Any help to guide me would be greatly appreciated.

Thanks!

回答1:

It is very simple

1) Create a new Java project in Eclipse.

2) Copy the the contents of "src" folder (downloaded from AlchemyAPI) into source folder of Eclipse project.

3) Build project.

4) "com.alchemyapi.test" package has sample test classes.

5) These classes read key from text file.

AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromFile("api_key.txt");

So the key which you received from AlchemyAPI in email should be written in a text file and give full path in above command.

6) Code refers sample html file contents as follows

String htmlDoc = getFileContents("data/example.html");

So you can change the path to your ".html" or ".txt" file to analyze.

While running the program make sure you have internet connectivity. Otherwise it will fail.