Retrofit 2 未找到注释
Retrofit 2 no annotation found
我正在尝试从 Firebase 获取特定数据。在客户端使用 REST API 和 Retrofit 2。
这是我在 Firebase 上的 JSON 结构:
{
"profiles" : {
"-KAG0XPBVNNF_RT55lwV" : {
"GCMTocken" : "rtdjhsrfjt546456",
"firstName" : "P",
"gender" : 1,
"lastName" : "Strongman",
"likes" : 0,
"nickname" : "drake1",
"uid" : "facebook:957484"
}
}
}
请求接口:
@GET("/profiles.json")
Observable<Profile> getProfile(@Query("orderBy") String key, @Query("equalTo") String uid);
根据这个请求,我总是得到:
java.lang.IllegalArgumentException: No Retrofit annotation found. (parameter #1)
for method FirebaseAPI.getProfile
编辑
我需要这个请求:
https://incandescent-torch-4.firebaseio.com/profiles.json?orderBy="uid"&equalTo="facebook:95748485767896"
我的改造设置:
String BASE_FIREBASE_URL = "https://incandescent-torch-4.firebaseio.com";
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constants.BASE_FIREBASE_URL)
.client(okHttpClient)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
restAPI = retrofit.create(FirebaseAPI.class);
来自 RxJava 的请求:
RestFirebaseClient.getInstance().getProfile(authData.getUid())
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<Profile>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Profile profile) {
}
});
将 Retrofit 2 依赖添加到 Gradle:
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
compile 'com.squareup.retrofit2:converter-jackson:2.0.0-beta3'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.0-RC1'
初始化改造:
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new HttpLoggingInterceptor()
.setLevel(HttpLoggingInterceptor.Level.BODY))
.addInterceptor(new TokenInterceptor())
.addInterceptor(new AuthenticationInterceptor())
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://your_url/")
.addConverterFactory(JacksonConverterFactory.create())
.client(client)
.build();
创建 Retrofit 服务,例如:
import retrofit2.Call;
import retrofit2.http.GET;
public interface ProfileService {
@GET("profile")
Call<User> get();
}
我用了@GET("profile")
,最后url是:http://your_url/profile
您可以尝试将 Observable<Profile>
更改为 Call<Profile>
并从 @GET("profiles.json")
中删除 .json
I observe in your code request @GET request just put "/" & make sure in you url you have to remove "/" at the end of url like -
like this -
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://incandescent-torch-4.firebaseio.com")
.addConverterFactory(GsonConverterFactory.create())
.build();
@GET("/profiles.json")
Observable<Profile> getProfile(@Query("orderBy") String key, @Query("equalTo") String uid);
这包含在 documentation 改造中。
我正在尝试从 Firebase 获取特定数据。在客户端使用 REST API 和 Retrofit 2。
这是我在 Firebase 上的 JSON 结构:
{
"profiles" : {
"-KAG0XPBVNNF_RT55lwV" : {
"GCMTocken" : "rtdjhsrfjt546456",
"firstName" : "P",
"gender" : 1,
"lastName" : "Strongman",
"likes" : 0,
"nickname" : "drake1",
"uid" : "facebook:957484"
}
}
}
请求接口:
@GET("/profiles.json")
Observable<Profile> getProfile(@Query("orderBy") String key, @Query("equalTo") String uid);
根据这个请求,我总是得到:
java.lang.IllegalArgumentException: No Retrofit annotation found. (parameter #1)
for method FirebaseAPI.getProfile
编辑
我需要这个请求:
https://incandescent-torch-4.firebaseio.com/profiles.json?orderBy="uid"&equalTo="facebook:95748485767896"
我的改造设置:
String BASE_FIREBASE_URL = "https://incandescent-torch-4.firebaseio.com";
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constants.BASE_FIREBASE_URL)
.client(okHttpClient)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
restAPI = retrofit.create(FirebaseAPI.class);
来自 RxJava 的请求:
RestFirebaseClient.getInstance().getProfile(authData.getUid())
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<Profile>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Profile profile) {
}
});
将 Retrofit 2 依赖添加到 Gradle:
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
compile 'com.squareup.retrofit2:converter-jackson:2.0.0-beta3'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.0-RC1'
初始化改造:
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new HttpLoggingInterceptor()
.setLevel(HttpLoggingInterceptor.Level.BODY))
.addInterceptor(new TokenInterceptor())
.addInterceptor(new AuthenticationInterceptor())
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://your_url/")
.addConverterFactory(JacksonConverterFactory.create())
.client(client)
.build();
创建 Retrofit 服务,例如:
import retrofit2.Call;
import retrofit2.http.GET;
public interface ProfileService {
@GET("profile")
Call<User> get();
}
我用了@GET("profile")
,最后url是:http://your_url/profile
您可以尝试将 Observable<Profile>
更改为 Call<Profile>
并从 @GET("profiles.json")
.json
I observe in your code request @GET request just put "/" & make sure in you url you have to remove "/" at the end of url like -
like this -
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://incandescent-torch-4.firebaseio.com")
.addConverterFactory(GsonConverterFactory.create())
.build();
@GET("/profiles.json")
Observable<Profile> getProfile(@Query("orderBy") String key, @Query("equalTo") String uid);
这包含在 documentation 改造中。