【发布时间】:2020-08-25 17:31:15
【问题描述】:
我已经使用 Firestore 实现了身份验证,它工作正常,现在通过 Google API 重做它并获得 http 状态“404”和空消息:
D/RESPONSE FIREBASE: Response{protocol=h2, code=404, message=, url=https://identitytoolkit.googleapis.com/v1/accounts/signInWithPassword?key=000080511101}
网络服务:
public class NetworkService {
private static NetworkService instance;
private static final String BASE_URL
= "https://identitytoolkit.googleapis.com/v1/";
private Retrofit retrofit;
private NetworkService() {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
public static NetworkService getInstance() {
if (instance == null) {
instance = new NetworkService();
}
return instance;
}
public PlaceHolderApi getJsonApi() {
return retrofit.create(PlaceHolderApi.class);
}
}
API
public interface PlaceHolderApi {
@FormUrlEncoded
@POST("accounts/signInWithPassword")
Call<Transaction.Result> loginWithEmail(
@Query("key") String key,
@Field("email") String email,
@Field("password") String password,
@Field("returnSecureToken") boolean returnSecureToken
);
}
用法:
NetworkService.getInstance()
.getJsonApi().loginWithEmail("000080511101", email, password, true)
.enqueue(new Callback<Transaction.Result>() {
@Override
public void onResponse(Call<Transaction.Result> call, Response<Transaction.Result> response) {
Log.d("RESPONSE FIREBASE", response.toString());
Log.d("RESPONSE MESSAGE", response.message());
}
@Override
public void onFailure(Call<Transaction.Result> call, Throwable t) {
t.printStackTrace();
}
});
文档说我应该使用内容类型 application/JSON,但是如何在这里使用它或使用改造通过 http 传递它? 任何指示都会有所帮助。
谢谢!
UPD:控制台查询结果
【问题讨论】:
-
能否分享一下您使用 Google API 所遵循的文档/指南?
-
@FerVelvet firebase.google.com/docs/reference/rest/…
标签: java android google-cloud-firestore google-api retrofit2