0

My purpose is to download the advertising report using existing application details such as AMAZON_CLIENT_ID, AMAZON_CLIENT_SECRET & Access tokens to other java application.

I was able to get the new access token using AMAZON_CLIENT_ID, AMAZON_CLIENT_SECRET & refresh_token. Below is the code to fetch a new access token.

OkHttpClient client = new OkHttpClient();
 Response response;
            MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
     RequestBody body = RequestBody.create(mediaType, "grant_type=refresh_token&refresh_token=" + refreshToken + "&client_id=" + amzClientId + "&client_secret=" + amzClientSceret);
            Request request = new Request.Builder()
                    .url(“https://api.amazon.com/auth/o2/token”)
                    .post(body)
                    .addHeader("content-type", "application/x-www-form-urlencoded")
                    .build();
        response = client.newCall(request).execute();

After sending the api request to fetch the campaign level stats data, is gives the following error

{"code":"UNAUTHORIZED","
details":"Not authorized to access scope XXXXXXXXXXXXXXXXXX","
requestId":"xxxxxxxxxxxxx"}" 

My question here is, Can I use the same existing AMAZON_CLIENT_ID, AMAZON_CLIENT_SECRET & Access tokens to fetch stats to different java applications(without using login with amazon)?

Any help would be appreciated. Thank you!!

Manju
  • 199
  • 1
  • 2
  • 10
  • Struggling with this myself right now. From the docs, it looks like you first have to get a profile id from the profiles endpoint. But that isn't working for me. Did you ever get this figured out? – user3076750 Jul 31 '21 at 01:41

1 Answers1

1

You need to include the access token and client ID for subsequent requests.

.addHeader("Authorization", "Bearer " + access_token)

.addHeader("Amazon-Advertising-API-ClientId", client_id)

mr_mooo_cow
  • 1,098
  • 1
  • 6
  • 16