GoogleAuthException:使用云端点进行身份验证时未知 [英] GoogleAuthException: Unknown when authenticating with Cloud Endpoints
问题描述
我正在尝试向我的云终端添加身份验证,但我无法使其正常工作。我使用这个博客作为指导: http://devthots.blogspot。 nl / 2012/07 / building-awesome-android-apps-with.html
我有:
在应用服务引擎项目:
@Api(名称= noteendpoint 的clientId = {123456789012-abcdefghijklmnopqrstuvwxyz012345 .apps.googleusercontent.com},audiences = {my_project_id.appspot.com},namespace = @ApiNamespace(ownerDomain =example.com,ownerName =example.com,packagePath =myapp))
public class NoteEndpoint {
//其余的类,为所有方法添加参数User。
}
在我的Android应用程序项目中:
Note note = new Note();
note.setDescription(Description!);
GoogleAccountCredential凭证=
GoogleAccountCredential.usingAudience(MainActivity.this,my_project_id.appspot.com);
credential.setSelectedAccountName(ACCOUNT_NAME);
note.setEmailAddress(credential.getSelectedAccountName());
生成器endpointBuilder = new Noteendpoint.Builder(
AndroidHttp.newCompatibleTransport(),
JacksonFactory(),凭证);
Noteendpoint endpoint = CloudEndpointUtils.updateBuilder(endpointBuilder).build();
注意结果= endpoint.insertNote(note).execute(); //抛出异常
当我运行这个时, GoogleAuthException:Unknown
被抛出:
07-08 14:16:45.677:E / AndroidRuntime(27381):由:com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAuthIOException
07-08 14:16:45.677:E / AndroidRuntime(27381):com.google.api.client.googleapis .extensions.android.gms.auth.GoogleAccountCredential $ RequestHandler.intercept(GoogleAccountCredential.java:308)
07-08 14:16:45.677:E / AndroidRuntime(27381):com.google.api.client。 http.HttpRequest.execute(HttpRequest.java:854)
07-08 14:16:45.677:E / AndroidRuntime(27381):在com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest .java:410)
07-08 14:16:45.677:E / AndroidRuntime(27381):com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
07-08 14:16:45.677 :E / AndroidRuntime(27381):com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
07-08 14:16:45.677:E / AndroidRuntime(27381) :at com.example.test.ui.MainActivity $ 1.doInBackground(MainActivity.java:131)
07-08 14:16:45.677:E / AndroidRuntime(27381):... 7 more
07-08 14:16:45.677:E / AndroidRuntime(27381):引起:com.google.android.gms.auth.GoogleAuthException:未知
07-08 14:16:45.677:E / AndroidRuntime(27381 ):at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
07-08 14:16:45.677:E / AndroidRuntime(27381):at com.google.android.gms.auth .GoogleAuthUtil.getToken(未知来源)
07-08 14:16:45.677:E / AndroidRuntime(27381):com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken (GoogleAccountCredential.java:277)
07-08 14:16:45.677:E / AndroidRuntime(27381):com.google.api.client.googleapis.extensions.android。 gms.auth.GoogleAccountCredential $ RequestHandler.intercept(GoogleAccountCredential.java:301)
我该如何解决这个问题?
用于 NoteEndpoint
类的clientId是从已安装应用程序的客户端ID中复制的, 使用 GoogleAccountCredential.usingAudience(MainActivity.this,server:client_id:my_project_id.appspot.com);
(所以用 server:client_id:
前缀)没有帮助。
使用
GoogleAccountCredential凭证= GoogleAccountCredential.usingAudience(MainActivity.this,服务器:CLIENT_ID:12312312312-abcdefghijklmnopqrstuvw012345678。 apps.googleusercontent.com);
和
@Api(名称= noteendpoint 的clientId = {Ids.WEB_CLIENT_ID,
Ids.ANDROID_CLIENT_ID},观众= {Ids.ANDROID_AUDIENCE},命名空间= @ApiNamespace(ownerDomain = example.com, OWNERNAME = example.com,packagepath的= 测试))
公共类NoteEndpoint {
公共类ID {
公共静态最终字符串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;
}
解决了这个问题。
I'm trying to add authentication to my Cloud Endpoints, but I can't get it to work. I'm using this blog as a guideline: http://devthots.blogspot.nl/2012/07/building-awesome-android-apps-with.html
What I have:
In the AppEngine project:
@Api(name = "noteendpoint", clientIds = { "123456789012-abcdefghijklmnopqrstuvwxyz012345.apps.googleusercontent.com" }, audiences = { "my_project_id.appspot.com" }, namespace = @ApiNamespace(ownerDomain = "example.com", ownerName = "example.com", packagePath = "myapp"))
public class NoteEndpoint {
// Rest of class, added parameter User to all methods.
}
In my Android app project:
Note note = new Note();
note.setDescription("Description!");
GoogleAccountCredential credential =
GoogleAccountCredential.usingAudience(MainActivity.this, "my_project_id.appspot.com");
credential.setSelectedAccountName(ACCOUNT_NAME);
note.setEmailAddress(credential.getSelectedAccountName());
Builder endpointBuilder = new Noteendpoint.Builder(
AndroidHttp.newCompatibleTransport(),
new JacksonFactory(), credential);
Noteendpoint endpoint = CloudEndpointUtils.updateBuilder(endpointBuilder).build();
Note result = endpoint.insertNote(note).execute(); // Exception thrown
When I run this, a GoogleAuthException: Unknown
is thrown:
07-08 14:16:45.677: E/AndroidRuntime(27381): Caused by: com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAuthIOException
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:308)
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:854)
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.example.test.ui.MainActivity$1.doInBackground(MainActivity.java:131)
07-08 14:16:45.677: E/AndroidRuntime(27381): ... 7 more
07-08 14:16:45.677: E/AndroidRuntime(27381): Caused by: com.google.android.gms.auth.GoogleAuthException: Unknown
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:277)
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:301)
How can I solve this?
The clientId used for the NoteEndpoint
class is copied from "Client id for installed applications", with my debug key sha1.
Using GoogleAccountCredential.usingAudience(MainActivity.this, "server:client_id:my_project_id.appspot.com");
(so with server:client_id:
prefixed) doesn't help.
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.
这篇关于GoogleAuthException:使用云端点进行身份验证时未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!