I want to use the API services from my java application.
I tried adding the dependency in my POM.xml file, but it is not in the maven repository.
So I downloaded the java SDK from Git, compiled it and imported the .jar file into my Maven library, that way I don't get any compilation errors.
add the code as it is in the "Read me" file, to the code in my application.
import com.telstra.ApiClient; import com.telstra.ApiException; import com.telstra.Configuration; import com.telstra.auth.OAuth; import com.telstra.messaging.*;
ApiClient defaultClient = Configuration.getDefaultApiClient(); defaultClient.setBasePath("https://tapi.telstra.com/v2"); // Configure OAuth2 access token for authorization OAuth auth = (OAuth) defaultClient.getAuthentication("auth"); AuthenticationApi authenticationApi = new AuthenticationApi(defaultClient); String clientId = "XYZ"; String clientSecret = "ABC"; String grantType = "client_credentials"; String scope = "NSMS"; try { OAuthResponse oAuthResponse = authenticationApi.authToken(clientId, clientSecret, grantType, scope); auth.setAccessToken(oAuthResponse.getAccessToken()); } catch (ApiException e) { System.err.println("Exception when calling AuthenticationApi#authToken"); System.err.println("Status code: " + e.getCode()); System.err.println("Reason: " + e.getResponseBody()); System.err.println("Response headers: " + e.getResponseHeaders()); e.printStackTrace(); }
But directly in the first line:
ApiClient defaultClient = Configuration.getDefaultApiClient();
get an exception error:
java.lang.NoClassDefFoundError: Could not initialize class com.telstra.Configuration
Clearly I am doing something wrong.
Can you help me, or give me a video or tutorial on how to integrate the API in my java application?
Hi Gabriel.
Sorry to hear that you are getting a run-time exception when using the JAVA SDK. This issue seem to be an isolated issue to your local setup pertaining to Java. I have requested one of our developers to check the reason behind the issue. In the mean time, could you please check below link?
https://stackoverflow.com/questions/17973970/how-to-solve-java-lang-noclassdeffounderror
Note: - Avoid sharing the details of client IDs and client keys in a public forum. I have removed them from your post above.
Regards
Vinodh
Thank you very much for removing my credentials.
Apparently I have everything fine, I will continue investigating, but if you can help me, you will make my work easier.
Thanks
If you could give me the Maven dependency, I think the problem would be fixed.
I already have the application working, it was my mistake.
Thanks
Glad to know that the issue has been resolved. Would you mind sharing the details with our community please?
Regards
Vinodh