Connect android backend endpoints and client using oauth2

I have a problem where I intend to authorize Android app with @ApiMethod on endpoint. I read a lot of documentation but I didn't solve the problem.

The main error I see in the logs is GoogleAuthException: Unknown.

I created a project in the Google Developers Console with two clients - one for Android and one for audience / web_id.

My client code in android:

mCredential = GoogleAccountCredential.usingAudience(this,"server:client_id:"+Constants.WEB_CLIENT_ID);


In onActivityResult get the account name:

    protected void onActivityResult(int requestCode, int resultCode,
                                    Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case REQUEST_ACCOUNT_PICKER:
                if (data != null && data.getExtras() != null) {
                    String accountName =
                    if (accountName != null) {



Then I create an AsyncTask for the endpoint method of the call and add the credentials:

        BpmApiRegister.Builder builder = new BpmApiRegister.Builder(AndroidHttp.newCompatibleTransport(),new JacksonFactory(),mCredential)
            User user = createUser();
            BpmApiRegister registerapi =;

        try {
            return registerapi.create(user).execute();//PROBLEM HERE
        } catch (Exception e) {


Endpoint code:

@Api(name = "bpmApiRegister",version = "v1",resource = "users", namespace = @ApiNamespace(
        ownerDomain = "",
        ownerName = "",
        packagePath = "" ))

public class UserRegisterEndpoint {

    private static final Logger logger = Logger.getLogger(UserRegisterEndpoint.class.getName());

    @ApiMethod(name = "create",path="users",httpMethod = ApiMethod.HttpMethod.POST,
            scopes = {BackendConstants.EMAIL_SCOPE},
            clientIds = {
            audiences = {BackendConstants.ANDROID_AUDIENCE})

    public User create(User user, userAuth) throws OAuthRequestException {


Error in execution endpoint method:

04-25 11:00:11.655  19784-19927/ W/System.err﹕ Unknown
04-25 11:00:11.655  19784-19927/  W/System.err﹕ at Source)
04-25 11:00:11.655  19784-19927/ W/System.err﹕ at Source)


To create android client_id I got a fingerprint and I put it in package (my app package).

To create a web_id, I put two urls http: // localhost: 8080 and ; and our corresponding redirect url add / oauth2callback


source to share

All Articles