Android Studio中的Android模拟器(Nexus)无法访问授权的api(来自Google云App Engine的终端)。 以下代码适用于物理设备,但不适用于模拟器:
credential = GoogleAccountCredential.usingAudience(context,
"server:client_id:" + "xyz-xyz.apps.googleusercontent.com");
credential.setSelectedAccountName("xyz@gmail.com");
builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(), new
AndroidJsonFactory(), credential).setRootUrl("https://babydo-xyz.appspot" +
".com/_ah/api/").setApplicationName("BackendTest");
以下错误显示Android监视器:
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: ch.appfactory.kusi.backendtest, PID: 8074
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
Caused by: java.lang.IllegalArgumentException: the name must not be empty: null
at android.accounts.Account.<init>(Account.java:48)
at com.google.android.gms.auth.zzd.getToken(Unknown Source)
at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
App Engine控制台显示没有服务器错误。
有趣的是,根据以下代码,模拟器可以访问api并且在没有实现身份验证时可以正常工作:
builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(), new
AndroidJsonFactory(), null).setRootUrl("https://babydo-xyz.appspot" +
".com/_ah/api/");
当模拟器进行经过身份验证的调用时,是否有人知道该考虑什么?
感谢您的回答