获取Alexa个人资料信息

时间:2017-09-08 10:53:56

标签: android alexa alexa-voice-service

我正在使用以下代码授权Alexa android应用程序。 如何从以下代码获取个人资料信息?

private static final String[] APP_SCOPES= {"alexa:all"};
String PRODUCT_DSN = Settings.Secure.getString(mContext.getContentResolver(),
                Settings.Secure.ANDROID_ID);
        Bundle options = new Bundle();
        String scope_data = "{\"alexa:all\":{\"productID\":\"" + mProductId +
                "\", \"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, getCodeChallenge());
        options.putString(AuthzConstants.BUNDLE_KEY.CODE_CHALLENGE_METHOD.val, "S256");
        options.putBoolean(AuthzConstants.BUNDLE_KEY.PROFILE.val, true);

        mAuthManager.authorize(APP_SCOPES, options, authListener);

1 个答案:

答案 0 :(得分:0)

最后我找到答案,需要获取访问令牌,然后调用api:

  

https://api.amazon.com/user/profile
  标题:授权",持票人   的access_token

例如:

String url = "https://api.amazon.com/user/profile";
OkHttpClient client = ClientUtil.getTLS12OkHttpClient();

Request request = new Request.Builder()
        .url(url)
        .addHeader("Authorization", "Bearer " + access_token)
        .build();

client.newCall(request).enqueue(new Callback() {
    @Override
    public void onFailure(Call call, final IOException e) {

    }

    @Override
    public void onResponse(Call call, Response response) throws IOException {
        String s = response.body().string();




    }
});