question

goodwilldd avatar image
goodwilldd asked

invaild access token? what's problem?

invaild access token? what's problem? When you run into here in the access token 403, and returns the invalid access token. You will know what is the problem? plz help me. my application ===================== private final String[] APP_SCOPES = {"profile"}; public AmazonAuthorizationManager getAmazonAuthorizationManager() { if (amazonAuthorizationManager == null) amazonAuthorizationManager = new AmazonAuthorizationManager(getApplicationContext(), Bundle.EMPTY); return amazonAuthorizationManager; } public void authorize() { getAmazonAuthorizationManager().authorize(APP_SCOPES, Bundle.EMPTY, authorizationListener); } public void getToken() { getAmazonAuthorizationManager().getToken(APP_SCOPES, tokenAuthorizationListener); } private AuthorizationListener authorizationListener = new AuthorizationListener() { final String prefix = "##### authorization ##### %s"; @Override public void onSuccess(Bundle response) { String authorizationCode = response.getString(AuthzConstants.BUNDLE_KEY.AUTHORIZATION_CODE.val); getPreferences().edit().putString(DemoApplication.authorizationCode, authorizationCode).apply(); } @Override public void onCancel(Bundle bundle) { Log.d(TAG, String.format(prefix, bundle)); } @Override public void onError(AuthError authError) { Log.e(TAG, String.format(prefix, authError.getMessage()), authError); } }; private AuthorizationListener tokenAuthorizationListener = new AuthorizationListener() { final String prefix = "##### accessToken ##### %s"; @Override public void onCancel(Bundle bundle) { Log.d(TAG, String.format(prefix, bundle)); } @Override public void onSuccess(Bundle bundle) { String token = bundle.getString(AuthzConstants.BUNDLE_KEY.TOKEN.val); getPreferences().edit().putString(DemoApplication.token, token).apply(); Log.d(TAG, String.format(prefix, token)); } @Override public void onError(AuthError authError) { Log.e(TAG, String.format(prefix, authError.getMessage()), authError); } }; ========================================= so, I succeeded receive the token! ========================================= package com.demoapplication.app.avs; import android.media.AudioFormat; import android.media.AudioRecord; import android.media.MediaRecorder; import android.util.Log; import com.demoapplication.app.DemoApplication; import org.apache.commons.fileupload.MultipartStream; import org.apache.commons.io.IOUtils; import javax.json.Json; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.Charset; import java.util.List; import java.util.Map; import java.util.concurrent.Callable; /** * Created by brandon on 2015-10-07. */ public abstract class AbstractAVSCallable implements Callable { public AbstractAVSCallable(DemoApplication application, String accessToken) { this.application = application; this.accessToken = accessToken; this.BUFFER_SIZE = AudioRecord.getMinBufferSize(AUDIO_RATE, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT); } protected final DemoApplication application; protected final String accessToken; protected final String TAG = AbstractAVSCallable.class.getName(); protected final String MPBOUND = "THISISTHEBOUNDARY1234"; protected final String LINEFEED = "\r\n"; protected final String BOUND = LINEFEED + "--" + MPBOUND + LINEFEED; protected final String END = LINEFEED + LINEFEED + "--" + MPBOUND + "--" + LINEFEED; protected final int CHUNK_LENGTH = 0; private HttpURLConnection mConnection; private DataOutputStream mOutputStream; protected AudioRecord mAudioRecord; protected boolean mIsRecording = false; protected final int AUDIO_RATE = 16000; protected byte[] data; protected int count = 0; protected final String url = " https://access-alexa-na.amazon.com/v1/avs/speechrecognizer/recognize/"; protected static final float MAX_REPORTABLE_AMP = 32767f; protected static final float MAX_REPORTABLE_DB = 90.3087f; protected double EMA_FILTER = 0.6; protected MediaRecorder mRecorder = null; protected double mEMA = 0.0; protected String output = null; protected int volumeLevelZeroCount = 0; protected int BUFFER_SIZE; public abstract AVSResponse call() throws Exception; protected DataOutputStream getOutputStream() { return mOutputStream; } protected HttpURLConnection getHttpURLConnection() { return mConnection; } protected void preparePost(String url, String accessToken) throws IOException{ mConnection = null; mOutputStream = null; URL obj = new URL(url); mConnection = (HttpURLConnection) obj.openConnection(); mConnection.setRequestMethod("POST"); mConnection.setRequestProperty("Authorization", "Bearer " + accessToken); mConnection.setRequestProperty("Host", " access-alexa-na.amazon.com"); mConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + MPBOUND); mConnection.setRequestProperty("Transfer-Encoding", "chunked"); mConnection.setChunkedStreamingMode(CHUNK_LENGTH); mConnection.setDoOutput(true); mOutputStream = new DataOutputStream(mConnection.getOutputStream()); String metadata = generateSpeechMetadata(); Log.d(TAG, "Sending 'POST' request to URL : " + obj.toString()); Log.d(TAG, "Metadata >> " + metadata); mOutputStream.writeBytes(BOUND + "Content-Disposition: form-data; name=\"request\"" + LINEFEED + "Content-Type: application/json; charset=UTF-8" + LINEFEED + LINEFEED); mOutputStream.write(metadata.getBytes(Charset.forName("UTF-8"))); mOutputStream.writeBytes(BOUND + "Content-Disposition: form-data; name=\"audio\"" + LINEFEED + "Content-Type: audio/L16; rate=16000; channels=1" + LINEFEED + LINEFEED); } protected AVSResponse completePost() throws IOException, AVSException { int responseCode = -1; InputStream response = null; InputStream error = null; try { mOutputStream.writeBytes(END); mOutputStream.flush(); mOutputStream.close(); responseCode = mConnection.getResponseCode(); Log.d(TAG, "Response Code : " + responseCode); logHeaders(mConnection.getHeaderFields()); response = mConnection.getInputStream(); String charSet = getHeaderParameter(mConnection.getHeaderField("Content-Type"), "charset", Charset.forName("UTF-8").displayName()); String responseBoundary = getHeaderParameter(mConnection.getHeaderField("Content-Type"), "boundary", null); if(responseBoundary == null){ return null; } return parseResponse(response, responseBoundary.getBytes(charSet)); } catch (IOException e) { if (mConnection != null) { error = mConnection.getErrorStream(); if (error != null) { throw new AVSException(responseCode + ": " + IOUtils.toString(error)); } } throw e; } finally { if(mOutputStream != null) { mOutputStream.close(); } if(response != null) { response.close(); } if(error != null) { error.close(); } } } private AVSResponse parseResponse(InputStream inpStr, byte[] boundary) throws IOException { MultipartStream mpStream = new MultipartStream(inpStr, boundary, 100000, null); Log.d(TAG, "Found initial boundary: " + mpStream.skipPreamble()); Log.d(TAG, mpStream.readHeaders()); ByteArrayOutputStream json = new ByteArrayOutputStream(); mpStream.readBodyData(json); Log.d(TAG, json.toString(Charset.defaultCharset().displayName())); AVSResponse response = new AVSResponse(Json.createReader(new ByteArrayInputStream(json.toByteArray()))); while (mpStream.readBoundary()) { String headers = mpStream.readHeaders(); Log.d(TAG, headers); ByteArrayOutputStream data = new ByteArrayOutputStream(); mpStream.readBodyData(data); if (!isJson(headers)) { response.addAudio(getCID(headers), new ByteArrayInputStream(data.toByteArray())); } else { Log.d(TAG, data.toString(Charset.defaultCharset().displayName())); } } return response; } private String getHeaderParameter(final String headerValue, final String key, final String defaultValue) { if (headerValue == null || key == null) { return null; } String[] parts = headerValue.split(";"); String value = defaultValue; for (String part : parts) { part = part.trim(); if (part.startsWith(key)) { value = part.substring(key.length() + 1).replaceAll("(^\")|(\"$)", "").trim(); } } return value; } private String getCID(String headers) { final String contentString = "Content-ID:"; BufferedReader reader = new BufferedReader(new StringReader(headers)); try { for (String line = reader.readLine(); line != null; line = reader.readLine()) { if (line.startsWith(contentString)) { return line.substring(contentString.length()).trim(); } } } catch (Exception e) { } return null; } private boolean isJson(String headers) { if (headers.contains("application/json")) { return true; } return false; } private void logHeaders(Map > map) { try { Log.d(TAG, "Response Headers:"); for (Map.Entry > entry : map.entrySet()) { Log.d(TAG, String.format("%s : %s",entry.getKey(), entry.getValue())); } } catch (IllegalStateException e) { e.printStackTrace(); } } private String generateSpeechMetadata() { return "{\n" + "\"messageHeader\": {\n" + "\"deviceContext\": [\n" + "{\n" + "\"name\": \"playbackState\",\n" + "\"namespace\": \"AudioPlayer\",\n" + "\"payload\": {\n" + "\"streamId\": \"\",\n" + "\"offsetInMilliseconds\": \"\",\n" + "\"playerActivity\": \"IDLE\"\n" + "}\n" + "}\n" + "]\n" + "},\n" + "\"messageBody\": {\n" + "\"profile\": \"helloworld_demo\",\n" + "\"locale\": \"en-us\",\n" + "\"format\": \"audio/L16; rate=16000; channels=1\"\n" + "}\n" + "}"; } } ============================= Implimention ============================= package com.demoapplication.app.avs.recoder; import android.media.MediaRecorder; import android.os.Environment; import android.util.Log; import com.demoapplication.app.DemoApplication; import com.demoapplication.app.avs.AVSResponse; import com.demoapplication.app.avs.AbstractAVSCallable; import java.io.File; import java.io.FileInputStream; import java.io.IOException; /** * Created by brandon on 2015-10-07. */ public class AVSMediaRecord extends AbstractAVSCallable { /** * Volume Check */ public AVSMediaRecord(DemoApplication applicatoin, String accessToken) { super(applicatoin, accessToken); this.output = Environment.getExternalStorageDirectory().getAbsolutePath() + "/audiodata"; this.data = new byte[BUFFER_SIZE]; } @Override public AVSResponse call() throws Exception { AVSResponse response = null; try { preparePost(url, accessToken); start(); mIsRecording = true; File file = new File(output); //ParcelFileDescriptor fileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); FileInputStream fileInputStream = new FileInputStream(file); int readCount = 0; while(mIsRecording){ readCount = fileInputStream.read(data); if ( readCount != -1 ) { try{ getOutputStream().write(data, 0, readCount); getOutputStream().flush(); int volumeLevel = getAmplitude(); Log.d(TAG, String.format("Current Volume Level :: %s - count : %s", volumeLevel, volumeLevelZeroCount)); switch (volumeLevel) { case 0: volumeLevelZeroCount++; break; default: volumeLevelZeroCount = 0; break; } if ( volumeLevelZeroCount > 100 ) { mIsRecording = false; stop(); } }catch (IOException e){ e.printStackTrace(); } } } response = completePost(); } catch (Exception e) { Log.e(TAG, "", e); } finally { } return response; } private void start() { try { if (mRecorder == null) { mRecorder = new MediaRecorder(); mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_WB); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB); mRecorder.setOutputFile(output); mRecorder.prepare(); mRecorder.start(); mEMA = 0.0; } } catch (IOException e) { Log.e(TAG, "IOException!!!", e); } } private void stop() { try { if (mRecorder != null) { mRecorder.stop(); mRecorder.release(); } } catch (Exception e) { Log.e(TAG, "", e); } } private int getAmplitude() { if (mRecorder != null) return (int) (mRecorder.getMaxAmplitude() / 2700.0); else return 0; } private double getAmplitudeEMA() { mEMA = EMA_FILTER * getAmplitude() + (1.0 - EMA_FILTER) * mEMA; return mEMA; } } ==================================== When you run into here in the access token 403, and returns the invalid access token. You will know what is the problem? plz help me.
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.

swasey@amazon avatar image
swasey@amazon answered
It looks like you're only requesting the "profile" scope. That scope only allows you to get email address and name (and maybe other details), but isn't enough to use AVS. You'll also need to request the "alexa:all" scope. Try that as well and let us know how it goes.
10 |5000

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

goodwilldd avatar image
goodwilldd answered
changed "profile" >> "alexa:all" AuthroizeCode ok~! but, i can't get accessToken Log...... ============================================= 10-08 10:45:58.685 6377-6377/com.skt.vuxdemo.app W/com.amazon.identity.auth.device.authorization.AuthorizationActivity﹕ onCreate 10-08 10:45:58.685 6377-6377/com.skt.vuxdemo.app D/com.amazon.identity.auth.device.authorization.AuthorizationActivity.PII﹕ Received response from WebBroswer for OAuth2 flow: 10-08 10:45:58.685 6377-6377/com.skt.vuxdemo.app D/com.amazon.identity.auth.device.authorization.AuthorizationResponseParser.PII﹕ Received response from WebBroswer for OAuth2 flow: 10-08 10:45:58.685 6377-6377/com.skt.vuxdemo.app D/com.amazon.identity.auth.device.authorization.AuthorizationResponseParser.PII﹕ Code extracted from response: 10-08 10:45:58.685 6377-6377/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.ScopesHelper﹕ Extracting scope string array from alexa:all+profile 10-08 10:45:58.685 6377-6377/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.AuthorizationHelper﹕ Return auth code success 10-08 10:45:58.685 6377-6377/com.skt.vuxdemo.app D/com.skt.vuxdemo.app.VUXDemoApplication﹕ ##### avs authorization ##### Bundle[{com.amazon.identity.auth.device.authorization.authorizationCode=ANRcMmESHEOArAdleTVt}] 10-08 10:46:25.130 6377-6377/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.api.AmazonAuthorizationManager﹕ com.skt.vuxdemo.app calling getToken : scopes=[alexa:all] 10-08 10:46:25.130 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.AbstractAppIdentifier﹕ isAPIKeyValid : packageName=com.skt.vuxdemo.app 10-08 10:46:25.130 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.AbstractAppIdentifier﹕ getAppInfo : packageName=com.skt.vuxdemo.app 10-08 10:46:25.130 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.AbstractAppIdentifier﹕ getAppInfoFromAPIKey : packageName=com.skt.vuxdemo.app 10-08 10:46:25.130 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.AbstractAppIdentifier﹕ Finding API Key for com.skt.vuxdemo.app 10-08 10:46:25.135 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.utils.ThirdPartyResourceParser﹕ Attempting to parse API Key from assets directory 10-08 10:46:25.135 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.APIKeyDecoder﹕ Begin decoding API Key for packageName=com.skt.vuxdemo.app 10-08 10:46:25.135 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.APIKeyDecoder﹕ getKeyParts for packageName=com.skt.vuxdemo.app 10-08 10:46:25.135 6377-7062/com.skt.vuxdemo.app D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII﹕ APIKey: 10-08 10:46:25.135 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.APIKeyDecoder﹕ verifySignature for packageName=com.skt.vuxdemo.app 10-08 10:46:25.135 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.APIKeyDecoder﹕ verifySignature Sha256 for packageName=com.skt.vuxdemo.app 10-08 10:46:25.175 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.APIKeyDecoder﹕ verifyPayload for packageName=com.skt.vuxdemo.app 10-08 10:46:25.175 6377-7062/com.skt.vuxdemo.app D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII﹕ Signature checking.: 10-08 10:46:25.175 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.APIKeyDecoder﹕ num sigs = 1 10-08 10:46:25.175 6377-7062/com.skt.vuxdemo.app D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII﹕ Fingerprint checking: 10-08 10:46:25.175 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.APIKeyDecoder﹕ num sigs = 1 10-08 10:46:25.175 6377-7062/com.skt.vuxdemo.app D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII﹕ Fingerpirints checking: 10-08 10:46:25.175 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.APIKeyDecoder﹕ scopes has no mapping in json, returning null array 10-08 10:46:25.180 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.APIKeyDecoder﹕ perm has no mapping in json, returning null array 10-08 10:46:25.190 6377-7062/com.skt.vuxdemo.app D/com.amazon.identity.auth.device.authorization.TokenHelper.PII﹕ GetToken pkg=com.skt.vuxdemo.app scopes=[alexa:all]: 10-08 10:46:25.190 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.AbstractAppIdentifier﹕ getAppInfo : packageName=com.skt.vuxdemo.app 10-08 10:46:25.190 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.AbstractAppIdentifier﹕ getAppInfoFromAPIKey : packageName=com.skt.vuxdemo.app 10-08 10:46:25.190 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.AbstractAppIdentifier﹕ Finding API Key for com.skt.vuxdemo.app 10-08 10:46:25.215 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.utils.ThirdPartyResourceParser﹕ Attempting to parse API Key from assets directory 10-08 10:46:25.215 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.APIKeyDecoder﹕ Begin decoding API Key for packageName=com.skt.vuxdemo.app 10-08 10:46:25.215 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.APIKeyDecoder﹕ getKeyParts for packageName=com.skt.vuxdemo.app 10-08 10:46:25.230 6377-7062/com.skt.vuxdemo.app D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII﹕ APIKey: 10-08 10:46:25.230 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.APIKeyDecoder﹕ verifySignature for packageName=com.skt.vuxdemo.app 10-08 10:46:25.230 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.APIKeyDecoder﹕ verifySignature Sha256 for packageName=com.skt.vuxdemo.app 10-08 10:46:25.240 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.APIKeyDecoder﹕ verifyPayload for packageName=com.skt.vuxdemo.app 10-08 10:46:25.245 6377-7062/com.skt.vuxdemo.app D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII﹕ Signature checking.: 10-08 10:46:25.250 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.APIKeyDecoder﹕ num sigs = 1 10-08 10:46:25.250 6377-7062/com.skt.vuxdemo.app D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII﹕ Fingerprint checking: 10-08 10:46:25.250 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.APIKeyDecoder﹕ num sigs = 1 10-08 10:46:25.250 6377-7062/com.skt.vuxdemo.app D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII﹕ Fingerpirints checking: 10-08 10:46:25.250 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.APIKeyDecoder﹕ scopes has no mapping in json, returning null array 10-08 10:46:25.255 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.appid.APIKeyDecoder﹕ perm has no mapping in json, returning null array 10-08 10:46:25.255 6377-7062/com.skt.vuxdemo.app D/com.amazon.identity.auth.device.endpoint.TokenVendor.PII﹕ Vending out token: appId=amzn1.application.3ccd1d6d8d2d4106808858964a5f7c32, scopes=[alexa:all]: 10-08 10:46:25.255 6377-7062/com.skt.vuxdemo.app W/com.amazon.identity.auth.device.endpoint.TokenVendor﹕ RequestedScope shouldn't be null!!!! - null, but continuing anyway... 10-08 10:46:25.260 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.endpoint.TokenVendor﹕ Try finding a common access token for requested scopes 10-08 10:46:25.265 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.endpoint.TokenVendor﹕ Try finding a common refresh token for requested scopes 10-08 10:46:25.270 6377-7062/com.skt.vuxdemo.app D/com.amazon.identity.auth.device.endpoint.TokenVendor.PII﹕ Updating existing token: 10-08 10:46:25.280 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ Unbinding Highest Versioned Service 10-08 10:46:25.280 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ Attempting to retrieve remote Android service. Ignore cached service=true 10-08 10:46:25.280 6377-7062/com.skt.vuxdemo.app D/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ getAuthorizationServiceInstance 10-08 10:46:25.280 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ Number of services found : 0 10-08 10:46:25.280 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ Number of MAP services to compare = 0 10-08 10:46:25.280 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ Returning no service to use 10-08 10:46:25.285 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ Attempting to retrieve remote Android service. Ignore cached service=true 10-08 10:46:25.285 6377-7062/com.skt.vuxdemo.app D/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ getAuthorizationServiceInstance 10-08 10:46:25.285 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ Number of services found : 0 10-08 10:46:25.285 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ Number of MAP services to compare = 0 10-08 10:46:25.285 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ Returning no service to use 10-08 10:46:25.285 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ Attempting to retrieve remote Android service. Ignore cached service=true 10-08 10:46:25.285 6377-7062/com.skt.vuxdemo.app D/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ getAuthorizationServiceInstance 10-08 10:46:25.285 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ Number of services found : 0 10-08 10:46:25.285 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ Number of MAP services to compare = 0 10-08 10:46:25.285 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ Returning no service to use 10-08 10:46:25.290 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ Attempting to retrieve remote Android service. Ignore cached service=false 10-08 10:46:25.290 6377-7062/com.skt.vuxdemo.app D/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ getAuthorizationServiceInstance 10-08 10:46:25.290 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ Number of services found : 0 10-08 10:46:25.290 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ Number of MAP services to compare = 0 10-08 10:46:25.290 6377-7062/com.skt.vuxdemo.app I/com.amazon.identity.auth.device.authorization.ThirdPartyServiceHelper﹕ Returning no service to use 10-08 10:46:25.295 6377-6381/com.skt.vuxdemo.app D/dalvikvm﹕ GC_CONCURRENT freed 535K, 7% free 9425K/10055K, paused 3ms+2ms 10-08 10:46:25.325 6377-7062/com.skt.vuxdemo.app D/com.skt.vuxdemo.app.VUXDemoApplication﹕ ##### avs accessToken ##### Bundle[{com.amazon.identity.auth.device.authorization.future.type=SUCCESS}] =============================================
10 |5000

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

swasey@amazon avatar image
swasey@amazon answered
You can't get an Authorization Code AND an Access Token. Why are you trying to get both? It looks like you're trying to write an Android app that makes direct speech calls to AVS, and not a companion application*. All you need for that use-case is the Access Token only. It's a little difficult to read your code, but it looks like you might have left out some code since it doesn't look like getToken() is called anywhere. I suggest you take a look at the sample application provided by the LWA team here: http://login.amazon.com/android and take a look at how Access Tokens are requested there. Then when making your call to AmazonAuthorizationManager#authorize() you need to pass the appropriate scope_data, like so: Bundle options = new Bundle(); String scope_data = "{\"alexa:all\":{\"productID\":\"" + PRODUCT_ID + "\", \"productInstanceAttributes\":{\"deviceSerialNumber\":\"" + PRODUCT_DSN + "\"}}}"; options.putString(AuthzConstants.BUNDLE_KEY.SCOPE_DATA.val, scope_data); mAuthManager.authorize(APP_SCOPES, options, new AuthorizeListener()); That should be enough to get you an Access Token. Looking at our AVS documentation I think it's misleading in describing how to do this, and I'll make sure to work with our doc writers to fix the issue so it's more clear. *By companion application I mean an application that's meant for setting up a separate device that may not have a screen. A companion app is for sending certain authorization items (the code) to the device which makes actual speech calls to AVS. This is discussed here: https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/docs/authorizing-your-alexa-enabled-product-from-an-android-or-ios-mobile-app
10 |5000

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

balzzz avatar image
balzzz answered
When I made a call to the AmazonAuthorizationManage.authorize() with the appropriate value and scope data. private static final String PRODUCT_ID="HelloWorldSample"; private static final String PRODUCT_DSN="1234"; private static final String[] APP_SCOPES= {"alexa:all"}; I am getting the following error. 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): AuthError during authorization 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): AuthError cat= INTERNAL type=ERROR_SERVER_REPSONSE - com.amazon.identity.auth.device.AuthError: Error=invalid_scope error_description=lwa-invalid-parameter-bad-scope 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): at com.amazon.identity.auth.device.authorization.AuthorizationResponseParser.constructErrorBundle(AuthorizationResponseParser.java:137) 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): at com.amazon.identity.auth.device.authorization.AuthorizationResponseParser.extractResultsBundle(AuthorizationResponseParser.java:83) 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): at com.amazon.identity.auth.device.authorization.AuthorizationActivity.onCreate(AuthorizationActivity.java:41) 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): at android.app.Activity.performCreate(Activity.java:5326) 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097) 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2215) 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2306) 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): at android.app.ActivityThread.access$700(ActivityThread.java:153) 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1286) 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): at android.os.Handler.dispatchMessage(Handler.java:99) 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): at android.os.Looper.loop(Looper.java:176) 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): at android.app.ActivityThread.main(ActivityThread.java:5302) 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): at java.lang.reflect.Method.invokeNative(Native Method) 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): at java.lang.reflect.Method.invoke(Method.java:511) 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 12-15 00:33:00.715: E/com.amazon.identity.auth.device.lwaapp.SampleLoginWithAmazonActivity(14239): at dalvik.system.NativeStart.main(Native Method) I can understand that the error is because of the APP_SCOPE.Can you please guide me.
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
What scope data are you sending? When you use LWA, you need to specify the scope (what "permission" you want), as well as scope data (extra information we need in order to grant you that permission). From your code sample that you pasted, I only see the scope you're requesting. Thanks, Eric
10 |5000

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

balzzz avatar image
balzzz answered
Actually this is the scope data which I am sending. Bundle options = new Bundle(); String scope_data = "{\"alexa:all\":{\"productID\":\"" + PRODUCT_ID + "\", \"productInstanceAttributes\":{\"deviceSerialNumber\":\"" + PRODUCT_DSN + "\"}}}"; options.putString(AuthzConstants.BUNDLE_KEY.SCOPE_DATA.val, scope_data); options.putBoolean(AuthzConstants.BUNDLE_KEY.GET_AUTH_CODE.val, true); options.putString(AuthzConstants.BUNDLE_KEY.CODE_CHALLENGE.val, CODE_CHALLENGE); options.putString(AuthzConstants.BUNDLE_KEY.CODE_CHALLENGE_METHOD.val, "S256"); amazonAuthManager.authorize(APP_SCOPES, options, new AuthorizeListener()); where the Product Id is the Id in the developer portal, CODE_CHALLENGE is the Security profile of the application. Is the error because of scope data which I am sending.
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
From what I saw, your code looks fine. Here are a couple things you can try: 1) Instead of sending a Bundle to authorize with all those options, send an empty Bundle. If you're still getting that error, it may be something wrong with your security profile 2) In edit product under security profile, verify that the security profile you're trying to use is correct (it should be listed in the dropdown). As a last resort, you can try creating a new security profile and then explicitly setting the product you're trying to authorize to that security profile.
10 |5000

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

balzzz avatar image
balzzz answered
Created a new security profile and everything works fine.Thanks a ton Eric
10 |5000

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