question

gmuhammad avatar image
gmuhammad asked

Get profile directly without calling AmazonAuthorizationManager.authorize

Hi, Assuming that user has configured his Amazon account on its Kindle device, is it valid and meaningful to call AmazonAuthorizationManager.getProfile(new ProfileListener()); from the app without calling mAuthManager.authorize(APP_SCOPES, Bundle.EMPTY, new AuthListener()); so that user is not shown the web login process and profile, user_id can be directly used? for example: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { mAuthManager = new AmazonAuthorizationManager(this, Bundle.EMPTY); mAuthManager.getProfile(new ProfileListener()); } catch(IllegalArgumentException e) { showAuthToast("APIKey is incorrect or does not exist."); Log.e(TAG, "Unable to Use Amazon Authorization Manager. APIKey is incorrect or does not exist.", e); } } private class ProfileListener implements APIListener { /** * Updates the profile view with data from the successful getProfile response. * Sets app state to logged in */ @Override public void onSuccess(Bundle response) { Log.d(TAG, "profile response: " + response.toString()); Bundle profileBundle = response.getBundle(AuthzConstants.BUNDLE_KEY.PROFILE.val); if(profileBundle == null){ runOnUiThread(new Runnable() { @Override public void run() { setLoggedOutState(); String errorMessage = "Error retrieving profile information.\nPlease log in again"; Toast errorToast = Toast.makeText(getApplicationContext(), errorMessage, Toast.LENGTH_LONG); errorToast.setGravity(Gravity.CENTER, 0, 0); errorToast.show(); } }); } else{ StringBuilder profileBuilder = new StringBuilder(); profileBuilder.append(String.format("Welcome, user_id: %s!\n", profileBundle.getString(AuthzConstants.PROFILE_KEY.USER_ID.val))); } } @Override public void onError(AuthError ae) { Log.e(TAG, ae.getMessage(), ae); runOnUiThread(new Runnable() { @Override public void run() { updateProfileView("ERROR: Request for profile information failed.\nPlease log out, and then try logging in again."); setLoggingInState(false); } }); } }
10 |5000

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

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Gmuhammad, Since you have posted in GameCircle forum, I am assuming that you are trying to integrate GameCircle in your app. Below is the sample code to access players profile from GameCircle SDK. AmazonGamesClient.getInstance().getProfilesClient() .getLocalPlayerProfile(new Object[]{}) .setCallback(new AGResponseCallback () { @Override public void onComplete(RequestPlayerProfileResponse result) { if (result.isError()) { Log.i(TAG, "GameCircleGetPlayerAlias ERROR: " + result.getError()); } else { Log.i(TAG, "GameCircleGetPlayerAlias OK"); String alias = result.getPlayer().getAlias(); Log.i(TAG, "alias: " + alias); Log.i(TAG, "playerid: " + result.getPlayer().getPlayerId()); } } }); Make sure this is called after GameCircle is initialized in the runtime. If you are using Login with Amazon feature (since you are using AmazonAuthorizationManager class from login-with-amazon-sdk.jar) then please write in the below forum since we do not support LWA sdk in this developer forum. https://sellercentral.amazon.com/forums/category.jspa?categoryID=23&start=0
10 |5000

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

gmuhammad avatar image
gmuhammad answered
Thank you! That helps me. Message was edited by: gmuhammad
10 |5000

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

priyatayde avatar image
priyatayde answered
Hello i also wants to do same thing so how i can Login in Amazon without using mAuthManager = new AmazonAuthorizationManager(this, Bundle.EMPTY); because it proceed me to web browser which i doesn't want and get User Profile Data in android Activity??
10 |5000

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

Sujoy@Amazon avatar image
Sujoy@Amazon answered
You seem to be using Login with Amazon (LWA) SDK. LWA is based on OAuth 2.0 so it is not possible to get user profile data without passing through the browser to login with their Amazon credentials. If you use GameCircle SDK and target your app only for Amazon devices, there you can retrieve user data (player id, avatar url and alias name) after initializing the GameCircle SDK (see my last post). https://developer.amazon.com/public/apis/engage/gamecircle/docs/integrate-gamecircle-apis-into-your-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.