SpringベースのアプリケーションサーバーでFirebase Cloud Messaging REST APIを使用して、プッシュメッセージをアプリケーションクライアントに送信しています。Firebaseプッシュ認証資格が無効です
私のIDEから実行すると、すべてが完全に機能します。 パッケージ化されたJARファイルから実行してプッシュメッセージを送信しようとすると、「認証情報が無効です」とステータスコード401が表示されます。
私のservice-account.jsonファイルは、クラスパスへ:私はまた、placiなどのサービス-account.jsonにアクセスするさまざまな方法を、試してみました
private String getAccessToken() throws IOException {
Resource resource = new ClassPathResource("service-account.json");
GoogleCredential googleCredential = GoogleCredential
.fromStream(resource.getInputStream())
.createScoped(Collections.singletonList("https://www.googleapis.com/auth/firebase.messaging"));
googleCredential.refreshToken();
return googleCredential.getAccessToken();
}
:私は、次の方法でそれをアクセスしていますが
プロジェクトのルートでそれをngのと、このようにそれを取得する:
private String getAccessToken() throws IOException {
File file = new File("service-account.json");
GoogleCredential googleCredential = GoogleCredential
.fromStream(new FileInputStream(file))
.createScoped(Collections.singletonList("https://www.googleapis.com/auth/firebase.messaging"));
googleCredential.refreshToken();
return googleCredential.getAccessToken();
}
とするとき、私はJARと同じフォルダに、JAR外サービスaccount.jsonファイルを供給パッケージ化JARから実行されています。 同じエラーが発生しました。
なぜこれが起こっているのか分かりません。何か助けや憶測がありがたいです。 application.propertiesで
@Value("${service.account.path}")
private String serviceAccountPath;
:
service.account.path = /path/to/service-account.json
とコード:
それをチェックしてください! https://groups.google.com/forum/#!topic/firebase-talk/i2sqxJIRzno –