question

keven1119 avatar image
keven1119 asked

InvalidAccessTokenException:AVS was not able to validate the provided acces

i get the accesstoken and request avs quick,but always response 403,InvalidAccessTokenException. after regist,i have never get the authorizationCode.
alexa voice service
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

keven1119 avatar image
keven1119 answered
*****this is the method i send a post request******** public static synchronized String doHttpsPost(Context ctx, String serverURL, String jsonStr)throws Exception { HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 3000); HttpConnectionParams.setSoTimeout(httpParameters, 3000); HttpClient hc = initHttpClient(httpParameters); HttpPost post = new HttpPost(serverURL); // post.addHeader("Content-Type", "application/json;charset=utf-8"); // // post.addHeader("Accept", "application/json"); String data = (String)SharePreferenceUtil.getData(ctx, Contant.ACCESS_TOKEN, ""); Log.d("keven","get access token==>"+data); // post.addHeader("Authorization","Bearer "+ data); post.addHeader("Authorization",data); post.addHeader("Content-Disposition","form-data; name=\"audio\""); post.addHeader("Content-Type","audio/L16; rate=16000; channels=1"); // post.addHeader("Transfer-Encoding","chunked"); StringEntity entity = new StringEntity(jsonStr, "UTF-8"); post.setEntity(entity); post.setParams(httpParameters); HttpResponse response = null; try { response = hc.execute(post); } catch (UnknownHostException e) { throw new Exception("Unable to access " + e.getLocalizedMessage()); } catch (SocketException e) { e.printStackTrace(); } int sCode = response.getStatusLine().getStatusCode(); Log.d(Contant.KEVEN,"response code==>"+sCode); Log.d(Contant.KEVEN,"response ==>"+EntityUtils.toString(response.getEntity())); if (sCode == HttpStatus.SC_OK) { return EntityUtils.toString(response.getEntity()); } else throw new Exception("StatusCode is " + sCode); }
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

keven1119 avatar image
keven1119 answered
02-05 16:54:33.734 31504-31504/com.o2fun.amazonlogin D/keven: appId==>amzn1.application.b4b07000286f47c5b8bace156158afc0 02-05 16:54:33.754 31504-31504/com.o2fun.amazonlogin D/keven: getClientId==>amzn1.application-oa2-client.f77a1e4d2cde43b284557e778d1f15d9 02-05 16:54:33.824 31504-31504/com.o2fun.amazonlogin D/keven: AppVariantId==>amzn1.application-client.5db43213e8c54bbea946fc07b1e6e63d 02-05 16:54:33.864 31504-31504/com.o2fun.amazonlogin D/keven: RedirectUri==>amzn://com.o2fun.amazonlogin 02-05 16:54:33.904 31504-31504/com.o2fun.amazonlogin D/keven: appId==>amzn1.application.b4b07000286f47c5b8bace156158afc0 02-05 16:54:33.924 31504-31504/com.o2fun.amazonlogin D/keven: AppVariantId==>amzn1.application-client.5db43213e8c54bbea946fc07b1e6e63d 02-05 16:54:33.934 31504-31504/com.o2fun.amazonlogin D/keven: getClientId==>amzn1.application-oa2-client.f77a1e4d2cde43b284557e778d1f15d9 02-05 16:54:33.944 31504-31504/com.o2fun.amazonlogin D/keven: RedirectUri==>amzn://com.o2fun.amazonlogin 02-05 16:55:45.814 31504-31504/com.o2fun.amazonlogin D/keven: appId==>amzn1.application.b4b07000286f47c5b8bace156158afc0 02-05 16:55:45.924 31504-31504/com.o2fun.amazonlogin D/keven: AppVariantId==>amzn1.application-client.5db43213e8c54bbea946fc07b1e6e63d 02-05 16:55:45.954 31504-31504/com.o2fun.amazonlogin D/keven: getClientId==>amzn1.application-oa2-client.f77a1e4d2cde43b284557e778d1f15d9 02-05 16:55:45.984 31504-31504/com.o2fun.amazonlogin D/keven: RedirectUri==>amzn://com.o2fun.amazonlogin 02-05 16:55:48.754 31504-32735/com.o2fun.amazonlogin D/keven: response==>Bundle[{com.amazon.identity.auth.device.authorization.authorize=authorized}] 02-05 16:55:48.754 31504-32735/com.o2fun.amazonlogin D/keven: authorizationCode==>null 02-05 16:55:49.864 31504-32734/com.o2fun.amazonlogin D/keven: authorizationCode==>null 02-05 16:55:49.864 31504-32734/com.o2fun.amazonlogin D/keven: response==>Bundle[{com.amazon.identity.auth.device.authorization.future.type=SUCCESS, com.amazon.identity.auth.device.authorization.profile=Bundle[{user_id=amzn1.account.AFEA776HQTDGJMXAQ6G52XK4ZYIQ, name=kevenliang, email=keven@o2fun.com}]}] 02-05 16:55:49.864 31504-32734/com.o2fun.amazonlogin D/keven: authorizationCode==>null 02-05 16:55:49.874 31504-32734/com.o2fun.amazonlogin D/keven: response==>Bundle[{com.amazon.identity.auth.device.authorization.future.type=SUCCESS, com.amazon.identity.auth.device.authorization.profile=Bundle[{user_id=amzn1.account.AFEA776HQTDGJMXAQ6G52XK4ZYIQ, name=kevenliang, email=keven@o2fun.com}]}] 02-05 16:55:49.874 31504-32734/com.o2fun.amazonlogin D/keven: name==>kevenliang 02-05 16:55:49.874 31504-32734/com.o2fun.amazonlogin D/keven: email==>keven@o2fun.com 02-05 16:55:49.874 31504-32734/com.o2fun.amazonlogin D/keven: account==>amzn1.account.AFEA776HQTDGJMXAQ6G52XK4ZYIQ 02-05 16:55:49.874 31504-32734/com.o2fun.amazonlogin D/keven: zipcode==>null 02-05 16:55:49.874 31504-31504/com.o2fun.amazonlogin D/keven: name==>kevenliang 02-05 16:55:49.874 31504-31504/com.o2fun.amazonlogin D/keven: email==>keven@o2fun.com 02-05 16:55:49.874 31504-31504/com.o2fun.amazonlogin D/keven: account==>amzn1.account.AFEA776HQTDGJMXAQ6G52XK4ZYIQ 02-05 16:55:49.874 31504-31504/com.o2fun.amazonlogin D/keven: zipcode==>null 02-05 16:56:28.804 31504-31504/com.o2fun.amazonlogin D/keven: appId==>amzn1.application.b4b07000286f47c5b8bace156158afc0 02-05 16:56:28.954 31504-31504/com.o2fun.amazonlogin D/keven: AppVariantId==>amzn1.application-client.5db43213e8c54bbea946fc07b1e6e63d 02-05 16:56:29.074 31504-31504/com.o2fun.amazonlogin D/keven: getClientId==>amzn1.application-oa2-client.f77a1e4d2cde43b284557e778d1f15d9 02-05 16:56:29.094 31504-31504/com.o2fun.amazonlogin D/keven: RedirectUri==>amzn://com.o2fun.amazonlogin 02-05 16:56:29.524 31504-32734/com.o2fun.amazonlogin D/keven: AUTH TOKEN==>Atza|IQEBLjAsAhRxxMYpWMyRS_cva6PlE846Rl91iQIUAOhpTKGPZwYdDMqOthQjVnTc7b368wy8tclKcRe5mVRpNakfaUKJEP3gWqqqUIPcLDXhDLjOQXkT_IHhALI-8wny9wVcy_3Q2qQL0KBsdln5cIcuTkNyYl7-MB3ykoydQAqLjunlvikLzxHEIxmcuxiymGgnODnGQHxDswn1-xL33d8BgfEuJkCTaxmbBqxC1Cjau7098nYBMTvqLKGK2C0b92s7qa85Jd3B1HW_y2mOPkN1atwsCrsgBNQ_ycTUQv0QLKN5K_8u2pcoUehdbQvBpHH79ifd5ZOWi52XhyWk0qpJ2QxVCEscAP3zK_cgCLfDo6y9rjHRnUD0M48rZ16SORkBZsTX2SPRx1qN--63SSUss7b8z1TZgapV7RJsoHgfcxs 02-05 16:56:29.524 31504-32734/com.o2fun.amazonlogin D/keven: wotamade TOKEN==>..................Atza|IQEBLjAsAhRxxMYpWMyRS_cva6PlE846Rl91iQIUAOhpTKGPZwYdDMqOthQjVnTc7b368wy8tclKcRe5mVRpNakfaUKJEP3gWqqqUIPcLDXhDLjOQXkT_IHhALI-8wny9wVcy_3Q2qQL0KBsdln5cIcuTkNyYl7-MB3ykoydQAqLjunlvikLzxHEIxmcuxiymGgnODnGQHxDswn1-xL33d8BgfEuJkCTaxmbBqxC1Cjau7098nYBMTvqLKGK2C0b92s7qa85Jd3B1HW_y2mOPkN1atwsCrsgBNQ_ycTUQv0QLKN5K_8u2pcoUehdbQvBpHH79ifd5ZOWi52XhyWk0qpJ2QxVCEscAP3zK_cgCLfDo6y9rjHRnUD0M48rZ16SORkBZsTX2SPRx1qN--63SSUss7b8z1TZgapV7RJsoHgfcxsAtza|IQEBLjAsAhRxxMYpWMyRS_cva6PlE846Rl91iQIUAOhpTKGPZwYdDMqOthQjVnTc7b368wy8tclKcRe5mVRpNakfaUKJEP3gWqqqUIPcLDXhDLjOQXkT_IHhALI-8wny9wVcy_3Q2qQL0KBsdln5cIcuTkNyYl7-MB3ykoydQAqLjunlvikLzxHEIxmcuxiymGgnODnGQHxDswn1-xL33d8BgfEuJkCTaxmbBqxC1Cjau7098nYBMTvqLKGK2C0b92s7qa85Jd3B1HW_y2mOPkN1atwsCrsgBNQ_ycTUQv0QLKN5K_8u2pcoUehdbQvBpHH79ifd5ZOWi52XhyWk0qpJ2QxVCEscAP3zK_cgCLfDo6y9rjHRnUD0M48rZ16SORkBZsTX2SPRx1qN--63SSUss7b8z1TZgapV7RJsoHgfcxsAtza|IQEBLjAsAhRxxMYpWMyRS_cva6PlE846Rl91iQIUAOhpTKGPZwYdDMqOthQjVnTc7b368wy8tclKcRe5mVRpNakfaUKJEP3gWqqqUIPcLDXhDLjOQXkT_IHhALI-8wny9wVcy_3Q2qQL0KBsdln5cIcuTkNyYl7-MB3ykoydQAqLjunlvikLzxHEIxmcuxiymGgnODnGQHxDswn1-xL33d8BgfEuJkCTaxmbBqxC1Cjau7098nYBMTvqLKGK2C0b92s7qa85Jd3B1HW_y2mOPkN1atwsCrsgBNQ_ycTUQv0QLKN5K_8u2pcoUehdbQvBpHH79ifd5ZOWi52XhyWk0qpJ2QxVCEscAP3zK_cgCLfDo6y9rjHRnUD0M48rZ16SORkBZsTX2SPRx1qN--63SSUss7b8z1TZgapV7RJsoHgfcxs 02-05 16:56:30.474 31504-1125/com.o2fun.amazonlogin D/keven: authorizationCode==>null 02-05 16:56:30.474 31504-1125/com.o2fun.amazonlogin D/keven: response==>Bundle[{com.amazon.identity.auth.device.authorization.future.type=SUCCESS, com.amazon.identity.auth.device.authorization.profile=Bundle[{user_id=amzn1.account.AFEA776HQTDGJMXAQ6G52XK4ZYIQ, name=kevenliang, email=keven@o2fun.com}]}] 02-05 16:56:30.484 31504-32735/com.o2fun.amazonlogin D/keven: response==>Bundle[{com.amazon.identity.auth.device.authorization.authorize=authorized}] 02-05 16:56:30.484 31504-32735/com.o2fun.amazonlogin D/keven: authorizationCode==>null 02-05 16:56:30.584 31504-32734/com.o2fun.amazonlogin D/keven: authorizationCode==>null 02-05 16:56:30.584 31504-32734/com.o2fun.amazonlogin D/keven: response==>Bundle[{com.amazon.identity.auth.device.authorization.future.type=SUCCESS, com.amazon.identity.auth.device.authorization.profile=Bundle[{user_id=amzn1.account.AFEA776HQTDGJMXAQ6G52XK4ZYIQ, name=kevenliang, email=keven@o2fun.com}]}] 02-05 16:56:30.584 31504-32734/com.o2fun.amazonlogin D/keven: authorizationCode==>null 02-05 16:56:30.584 31504-32734/com.o2fun.amazonlogin D/keven: response==>Bundle[{com.amazon.identity.auth.device.authorization.future.type=SUCCESS, com.amazon.identity.auth.device.authorization.profile=Bundle[{user_id=amzn1.account.AFEA776HQTDGJMXAQ6G52XK4ZYIQ, name=kevenliang, email=keven@o2fun.com}]}] 02-05 16:56:30.584 31504-32734/com.o2fun.amazonlogin D/keven: name==>kevenliang 02-05 16:56:30.584 31504-32734/com.o2fun.amazonlogin D/keven: email==>keven@o2fun.com 02-05 16:56:30.584 31504-32734/com.o2fun.amazonlogin D/keven: account==>amzn1.account.AFEA776HQTDGJMXAQ6G52XK4ZYIQ 02-05 16:56:30.584 31504-32734/com.o2fun.amazonlogin D/keven: zipcode==>null 02-05 16:56:30.584 31504-31504/com.o2fun.amazonlogin D/keven: name==>kevenliang 02-05 16:56:30.584 31504-31504/com.o2fun.amazonlogin D/keven: email==>keven@o2fun.com 02-05 16:56:30.584 31504-31504/com.o2fun.amazonlogin D/keven: account==>amzn1.account.AFEA776HQTDGJMXAQ6G52XK4ZYIQ 02-05 16:56:30.584 31504-31504/com.o2fun.amazonlogin D/keven: zipcode==>null 02-05 16:56:43.694 31504-1293/com.o2fun.amazonlogin D/keven: response code==>403 02-05 16:56:43.694 31504-1293/com.o2fun.amazonlogin D/keven: response ==>{"error":{"code":"com.amazon.alexahttpproxy.exceptions.InvalidAccessTokenException","message":"AVS was not able to validate the provided access token."}}
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

elstryan@Amazon avatar image
elstryan@Amazon answered
Hi Kevin, One likely cause of this error code is that you are using a security profile that is not associated with an Alexa Voice Service product. Please view the product you have registered at https://developer.amazon.com/edw/home.html#/avs/list and click edit and then security profile and verify that you are using the security profile listed there in your android application. One more point: it looks like you are performing all of this code on an android device using the LWA android SDK (please correct me if this is not the case). I.e. your user will authenticate on your android application AND make requests to AVS on your android device. If that is the case there is a more direct way to fetch down the token. Please take a look at the following related posted: http://forums.developer.amazon.com/forums/thread.jspa?threadID=9532&tstart=0 and follow the code sample for "AVS app ONLY". Using that you should be able to get a token more directly (you need not worry about getting the profile information either - unless you require it for some reason) Thanks, Ryan V
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

keven1119 avatar image
keven1119 answered
is there a way to use avs without regist by the user? any way,is there any problem of the code i send requst to avs.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Eric@Amazon avatar image
Eric@Amazon answered
Currently, AVS requires a registered user in order to use it. As far as your code goes, there are a couple things. The authorization header does need "Bearer." It doesn't appear as though you are sending a multipart request (I see no mention of boundaries). You should use this example request as a guide: https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/rest/speechrecognizer-requests Also, you might want to look into libraries that would make multipart HTTP requests easier to use.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

keven1119 avatar image
keven1119 answered
i can get token,it doesn't mean that my security profile is associated ? and i only send a Audio multipart request ,deos it need to send all like the example POST /v1/avs/speechrecognizer/xxxxxxxxxxxx HTTP/1.1 Host: access-alexa-na.amazon.com Authorization: Bearer xxxxxxxxxxxx Content-Type: multipart/form-data; boundary=boundary_term Transfer-Encoding: chunked --boundary_term Content-Disposition: form-data; name="request" Content-Type: application/json; charset=UTF-8 { "messageHeader": { "deviceContext": [ { "name": "playbackState", "namespace": "AudioPlayer" "payload": { "streamId": "xxxxxxxxxxxx", "offsetInMilliseconds": xxxxxxxxxxxx, "playerActivity": "xxxxxxxxxxxx" } }, { ... }, ... ] }, "messageBody": { "profile": "alexa-close-talk", "locale": "en-us", "format": "audio/L16; rate=16000; channels=1" } } --boundary_term Content-Disposition: form-data; name="audio" Content-Type: audio/L16; rate=16000; channels=1 ...encoded_audio_data... --boundary_term-- or only send POST /v1/avs/speechrecognizer/xxxxxxxxxxxx HTTP/1.1 Host: access-alexa-na.amazon.com Authorization: Bearer xxxxxxxxxxxx Content-Type: multipart/form-data; boundary=boundary_term Transfer-Encoding: chunked --boundary_term Content-Disposition: form-data; name="audio" Content-Type: audio/L16; rate=16000; channels=1 ...encoded_audio_data... --boundary_term--
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Eric@Amazon avatar image
Eric@Amazon answered
Getting an access token does not necessarily mean that you have a correctly associated security profile. That's something you can only check through the developer portal, as mentioned above. To answer your other question, the audio data is essentially an attachment to your actual request, which is the JSON data. You must send *both* in order to get a response back from AVS.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.