aez*_*aez 4 android google-cloud-endpoints
我在Google Cloud Endpoints Android应用中首次尝试在调试模式下使用身份验证时遇到问题.我设置了这样的凭据:
credential = GoogleAccountCredential.usingAudience(this,
"server:client_id:long-string-i-got-from-api-console");
credential.setSelectedAccountName(accountName);
Run Code Online (Sandbox Code Playgroud)
然后尝试像这样使用它:
final String LOCAL_APP_ENGINE_SERVER_URL = "http://xxx.xxx.x.xxx:8888";
Testdbendpoint.Builder endpointBuilder = new Testdbendpoint.Builder(
AndroidHttp.newCompatibleTransport(),
new GsonFactory(),
credential);
endpointBuilder.setRootUrl(LOCAL_APP_ENGINE_SERVER_URL + "/_ah/api/");
Testdbendpoint endpoint = endpointBuilder.build();
try {
TestDB testDB = new TestDB().setId(10101L);
TestDB result = endpoint.insertTestDB(testDB).execute(); //-- fails here!!!!
} catch ...
Run Code Online (Sandbox Code Playgroud)
但尝试失败,我在logCat中收到这些消息:
03-06 23:33:20.418:W/System.err(11861):引起:com.google.android.gms.auth.GoogleAuthException:Unknown 03-06 23:33:20.418:W/System.err(11861) ):at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)03-06 23:33:20.423:W/System.err(11861):at com.google.android.gms.auth.GoogleAuthUtil .getToken(Unknown Source)03-06 23:33:20.428:W/System.err(11861):at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java) :192)
Nip*_*per 12
也许你的Android Client-Id有错误的证书指纹(SHA1)?只有在手动签署.apk时,才能使用生产密钥的指纹进行身份验证.
在API控制台中使用debug.keystore指纹为已安装的应用程序(Android)注册Client-Id .要获得指纹使用:
C:\>keytool -list -alias androiddebugkey -keystore C:\.android\debug.keystore -storepass android -keypass android
Run Code Online (Sandbox Code Playgroud)
您还需要一个Web-Client-Id并在Android应用程序中将其设置为Audience:
credential = GoogleAccountCredential.usingAudience(this,"server:client_id:" + WEB_CLIENT_ID);
Run Code Online (Sandbox Code Playgroud)
AppEngine端点配置应如下所示:
@Api(
name = "testEndpoint",
version = "v1",
clientIds = {ClientIds.WEB_ID, ClientIds.ANDROID_PRODUCTION_ID, ClientIds.ANDROID_DEBUG_ID},
audiences = {ClientIds.WEB_ID}
Run Code Online (Sandbox Code Playgroud)
)
| 归档时间: |
|
| 查看次数: |
3285 次 |
| 最近记录: |