我正在为一个Android移动SDK设计API测试.为了实现SDK功能,我需要提供一个身份令牌,而这个身份令牌目前是Google.通过调用Google签到活动,在那里通过UI交互登录,并从签到意图结果中获取令牌,这样做(获取令牌)没有问题。(https:/developers.google.comidentitysign-inandroid。)
但由于这是唯一一个会出现在所有测试中的UI交互,肯定要把它去掉,所以我想找的是。
有没有什么办法可以通过API来代替UI登录?只需要在代码中向相应的方法提供邮箱和密码就可以了。
我找不到任何这样做的参考资料。
我也面临着类似的问题,我想把登录和UI分离开来。GoogleSignInClient.silentSignIn()看起来很有前途,但我还没能检查它是否有效。这里有一些文档 https:/developers.google.comandroidreferencecomgoogleandroidgmsauthapisigninGoogleSignInClient#silentSignIn() 还有一个实施样本,它看起来像这样。
Task<GoogleSignInAccount> task = googleSignInClient.silentSignIn();
if (task.isSuccessful()) {
// There's immediate result available.
GoogleSignInAccount signInAccount = task.getResult();
updateViewWithAccount(account);
} else {
// There's no immediate result ready, displays some progress indicator and waits for the
// async callback.
showProgressIndicator();
task.addOnCompleteListener(new OnCompleteListener<GoogleSignInAccount>() {
@Override
public void onComplete(Task<GoogleSignInAccount> task) {
try {
hideProgressIndicator();
GoogleSignInAccount signInAccount = task.getResult(ApiException.class);
updateViewWithAccount(account);
} catch (ApiException apiException) {
// You can get from apiException.getStatusCode() the detailed error code
// e.g. GoogleSignInStatusCodes.SIGN_IN_REQUIRED means user needs to take
// explicit action to finish sign-in;
// Please refer to GoogleSignInStatusCodes Javadoc for details
updateButtonsAndStatusFromErrorCode(apiException.getStatusCode());
}
}
});
}