Access youtube account with accountmanager

前端 未结 3 1367
伪装坚强ぢ
伪装坚强ぢ 2020-12-15 02:16

Im trying to access youtube account with account manager, meaning i want to access youtube with a account linked to my device and with this get youtube token to access user

3条回答
  •  醉话见心
    2020-12-15 02:50

    you're in luck as I just finished cracking this problem on the app I'm developing.

    AccountManager.get(getApplicationContext()).getAuthTokenByFeatures("com.google", "oauth2:https://gdata.youtube.com", null, this,
        null, null, new AccountManagerCallback() {
    
            @Override
            public void run(AccountManagerFuture future) {
            try {
                Bundle bundle = future.getResult();
                String acc_name = bundle.getString(AccountManager.KEY_ACCOUNT_NAME);
                String auth_token = bundle.getString(AccountManager.KEY_AUTHTOKEN);
    
                Log.d(DEBUG_TAG, "name: " + acc_name + "; token: " + auth_token);
    
            } catch (Exception e) {
                Log.e(DEBUG_TAG, e.getClass().getSimpleName() + ": " + e.getMessage());
            }
            }
        }, null);
    

提交回复
热议问题