GoogleAuthException: Unknown when authenticating with Cloud Endpoints

我与影子孤独终老i 提交于 2019-12-03 07:17:17

Be careful when you generate the Android Client ID. When you enter the package name, use the application ID written in app/build.gradle. It may be different of the package for your sources classes.

Explanation:

At the project creation, the package name you enter is used by Android as Application ID and used to generate packages for your source classes. During the project development, you may change the package name for your source classes. But be careful, Android Studio doesn't change automatically your application ID !

Using

GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(MainActivity.this, "server:client_id:12312312312-abcdefghijklmnopqrstuvw012345678.apps.googleusercontent.com");

and

@Api(name = "noteendpoint", clientIds = { Ids.WEB_CLIENT_ID,
        Ids.ANDROID_CLIENT_ID }, audiences = { Ids.ANDROID_AUDIENCE }, namespace = @ApiNamespace(ownerDomain = "example.com", ownerName = "example.com", packagePath = "test"))
public class NoteEndpoint {

    public class Ids {
        public static final String WEB_CLIENT_ID = "12312312312312-abcdefghijklmnopqrstuvwxyz012345678.apps.googleusercontent.com";
        public static final String ANDROID_CLIENT_ID = "12312312312312-0123456789abcdefghabcdefghabcdefgha.apps.googleusercontent.com";
        public static final String ANDROID_AUDIENCE = WEB_CLIENT_ID;
    }

solved the problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!