fxjordan / botometer-java

Java library to detect Twitter bot accounts using the Botometer API. Botometer is a bot detection service for Twitter accounts developed by OSoMe.
https://botometer.iuni.iu.edu
Apache License 2.0
4 stars 3 forks source link

API error (statusCode: 404): null - API doesn't exists #4

Closed xuan closed 4 years ago

xuan commented 4 years ago

I'm getting "API doesn't exists" in your code DefaultBotometerClient when you make the call to:

` RequestBody body = RequestBody.create(JSON_MEDIA_TYPE, accountDataJson); Request request = new Request.Builder().url(BOTOMETER_CHECK_ACCOUNT_URL).header("X-RapidAPI-Key", this.apiKey) .post(body).build();

    try (Response response = this.httpClient.newCall(request).execute()) {
        if (response.isSuccessful()) {
            return readClassifcationResult(response.body());
        } else {
            throw createApiErrorException(response);
        }
    }

`

Here is my code ` BotometerConfiguration config = new BotometerConfigurationBuilder() .botometerApiKey("...") .twitterConsumerKey("...") .twitterConsumerSecret("...") .twitterAccessToken("...") .twitterAccessTokenSecret("...").build(); Botometer botometer = new BotometerFactory(config).create();

    AccountAnalysisResult result = botometer.analyzeAccount("realDonaldTrump");
    log.debug("result: {}",result);

`

I'm getting the following exception:

at de.fjobilabs.botometer.AccountAnalyzingBotometer.analyzeAccountData(AccountAnalyzingBotometer.java:85) at de.fjobilabs.botometer.AccountAnalyzingBotometer.analyzeAccount(AccountAnalyzingBotometer.java:72) at com.xuan.bot.service.BotMeterServiceTest.testAnalyzeTwitterAccount(BotMeterServiceTest.java:24) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:686) at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60) at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131) at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84) at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115) at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105) at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37) at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104) at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:212) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:208) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:137) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:71) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) at java.base/java.util.ArrayList.forEach(ArrayList.java:1510) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) at java.base/java.util.ArrayList.forEach(ArrayList.java:1510) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:248) at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211) at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58) Caused by: de.fjobilabs.botometer.api.BotometerApiException: API error (statusCode: 404): null - API doesn't exists at de.fjobilabs.botometer.api.BotometerApiException.create(BotometerApiException.java:75) at de.fjobilabs.botometer.client.DefaultBotometerClient.createApiErrorException(DefaultBotometerClient.java:87) at de.fjobilabs.botometer.client.DefaultBotometerClient.checkAccount(DefaultBotometerClient.java:70) at de.fjobilabs.botometer.client.AbstractBotometerClient.checkAccountDTO(AbstractBotometerClient.java:79) at de.fjobilabs.botometer.client.AbstractBotometerClient.checkAccount(AbstractBotometerClient.java:74) at de.fjobilabs.botometer.AccountAnalyzingBotometer.analyzeAccountData(AccountAnalyzingBotometer.java:83) ... 65 more

fxjordan commented 4 years ago

Hi, thanks for your report. I have briefly checked and it seems like they changed the API endpoint at RapidAPI. Now all API calls (free and pro) should go to the 'botometer-pro' endpoint (https://rapidapi.com/OSoMe/api/botometer-pro).

Unfortunately, the URL is hardcoded at the moment: https://github.com/fxjordan/botometer-java/blob/0c75bdc900672a20a2daede062733afa427b0db5/botometer-client/src/main/java/de/fjobilabs/botometer/client/DefaultBotometerClient.java#L46

We should make the URL configurable through BotometerConfiguration and provide the new URL as a default value.

fxjordan commented 4 years ago

I'll try to make a new release asap. For now, you can build the snapshot version yourself locally.