我尝试使用火基消息服务器设置设备组 我按照文档的步骤,但在获取id令牌的步骤 我收到此错误,我找不到似乎有效的解决方案 文档链接:https://firebase.google.com/docs/cloud-messaging/android/device-group
com.google.android.gms.auth.GoogleAuthException: INVALID_AUDIENCE
以下是我使用的代码:
private String getAccount() {
Account[] accounts = AccountManager.get(context).getAccountsByType("com.google");
if (accounts.length == 0) {
return null;
}
return accounts[0].name;
}
private class GetAuthToke extends AsyncTask<Void, Void, Void> {
String idToken = null;
@Override
protected Void doInBackground(Void... params) {
String accountName = getAccount();
// Initialize the scope using the client ID you got from the Console.
final String scope = "audience:server:client_id:"
+ "*****.apps.googleusercontent.com";
try {
idToken = GoogleAuthUtil.getToken(context, accountName, scope);
// } catch (Exception e) {
// e.printStackTrace();
// System.out.println("exception while getting idToken: " + e.toString());
// }
} catch (UserRecoverableAuthException e) {
// startActivityForResult(e.getIntent(), 888);
e.printStackTrace();
} catch (GoogleAuthException | IOException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void unused) {
try {
System.out.println("nasef " + idToken);
} catch (Exception e) {
}
}
}
记录:
com.google.android.gms.auth.GoogleAuthException: INVALID_AUDIENCE
com.google.android.gms.auth.zze$1.zzbt(Unknown Source)
com.google.android.gms.auth.zze$1.zzbu(Unknown Source)
com.google.android.gms.auth.zze.zza(Unknown Source)
com.google.android.gms.auth.zze.zzc(Unknown Source)
com.google.android.gms.auth.zze.getToken(Unknown Source)
com.google.android.gms.auth.zze.getToken(Unknown Source)
com.google.android.gms.auth.zze.getToken(Unknown Source)
com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
com.mivors.customerservice.mivorscustomerservice.utils.pushNotifications.FirebaseRequest$GetAuthToke.doInBackground(FirebaseRequest.java:126)
com.mivors.customerservice.mivorscustomerservice.utils.pushNotifications.FirebaseRequest$GetAuthToke.doInBackground(FirebaseRequest.java:116)
android.os.AsyncTask$2.call(AsyncTask.java:288)
java.util.concurrent.FutureTask.run(FutureTask.java:237)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
java.lang.Thread.run(Thread.java:818)
com.google.android.gms.auth.GoogleAuthException: INVALID_AUDIENCE
com.google.android.gms.auth.zze$1.zzbt(Unknown Source)
com.google.android.gms.auth.zze$1.zzbu(Unknown Source)
com.google.android.gms.auth.zze.zza(Unknown Source)
com.google.android.gms.auth.zze.zzc(Unknown Source)
com.google.android.gms.auth.zze.getToken(Unknown Source)
com.google.android.gms.auth.zze.getToken(Unknown Source)
com.google.android.gms.auth.zze.getToken(Unknown Source)
com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
com.mivors.customerservice.mivorscustomerservice.utils.pushNotifications.FirebaseRequest$GetAuthToke.doInBackground(FirebaseRequest.java:126)
com.mivors.customerservice.mivorscustomerservice.utils.pushNotifications.FirebaseRequest$GetAuthToke.doInBackground(FirebaseRequest.java:116)
android.os.AsyncTask$2.call(AsyncTask.java:288)
java.util.concurrent.FutureTask.run(FutureTask.java:237)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
java.lang.Thread.run(Thread.java:818)