Adobe-Marketing-Cloud / analytics-java-library

A Java client library for Analytics APIs
Apache License 2.0
15 stars 16 forks source link

Authentication problems #28

Open martin-g opened 5 years ago

martin-g commented 5 years ago

Hi,

I am trying to use this library and I am having problems to use the OAuth authentication.

My code is:


    private static final String CLIENT_ID = "MY_CLIENT_ID_HERE";
    private static final String CLIENT_SECRET = "MY_SECRET_HERE";

    public static void main(String[] args) throws Exception {
        AnalyticsClient client = new AnalyticsClientBuilder()
                .setEndpoint("api2.omniture.com")
                .authenticateWithClientCredentialsOAuth(CLIENT_ID, CLIENT_SECRET)
                .build();

        ReportSuiteMethods suiteMethods = new ReportSuiteMethods(client);
        CompanyReportSuites reportSuites = suiteMethods.getReportSuites();
        for (CompanyReportSuite suite : reportSuites.getReportSuites()) {
            System.out.println("Suite: " + suite);
        }
  }

Pretty much as in the README: https://github.com/Adobe-Marketing-Cloud/analytics-java-library/blob/master/README.md#L176-L179

But it fails with:

Exception in thread "main" com.adobe.granite.analytics.client.ApiException: invalid_client (The client credentials are invalid)
    at com.adobe.granite.analytics.client.ConnectionUtil.readResponse(ConnectionUtil.java:25)
    at com.adobe.granite.analytics.client.auth.OAuthenticator.getToken(OAuthenticator.java:63)
    at com.adobe.granite.analytics.client.auth.OAuthenticator.authenticate(OAuthenticator.java:44)
    at com.adobe.granite.analytics.client.AnalyticsClient.callMethod(AnalyticsClient.java:43)
    at com.adobe.granite.analytics.client.AnalyticsClient.callMethod(AnalyticsClient.java:31)
    at com.adobe.granite.analytics.client.methods.ReportSuiteMethods.getReportSuites(ReportSuiteMethods.java:34)
    at test.AdobeDriver.main(AdobeDriver.java:41)

I get the CLIENT_ID and the SECRET_ID from https://console.adobe.io/integrations/XXXXX/YYYYY/overview (XXXXX and YYYYY are numbers).

What could be the problem ? Is it that this library still uses the 1.4 APIs - https://github.com/Adobe-Marketing-Cloud/analytics-java-library/blob/6f4a9b6900b7555d2a32ba3394e156b956d9d3d5/src/main/java/com/adobe/granite/analytics/client/AnalyticsClient.java#L48 ?

Should I follow the JWT approach (https://github.com/AdobeDocs/analytics-2.0-apis/tree/master/examples/jwt/java) ?

martin-g commented 5 years ago

To answer myself: the JWT approach do work! It seems this library is obsolete!

@Adobe-Marketing-Cloud/team: Please add a red/bold note at the top of the README that it is not useful anymore.