0

I am trying get specific data from Firebase. Using REST API and Retrofit 2 on client side.

Here is my JSON structure on Firebase:

{
"profiles" : {
"-KAG0XPBVNNF_RT55lwV" : {
  "GCMTocken" : "rtdjhsrfjt546456",
  "firstName" : "P",
  "gender" : 1,
  "lastName" : "Strongman",
  "likes" : 0,
  "nickname" : "drake1",
  "uid" : "facebook:957484"
}
}
}

Request interface:

@GET("/profiles.json")
Observable<Profile> getProfile(@Query("orderBy") String key, @Query("equalTo") String uid);

On this request i always get:

java.lang.IllegalArgumentException: No Retrofit annotation found. (parameter #1) 
for method FirebaseAPI.getProfile

EDIT

i need this request:

https://incandescent-torch-4.firebaseio.com/profiles.json?orderBy="uid"&equalTo="facebook:95748485767896"

My retrofit setup:

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);

Request from 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) {

                            }
                        });
Pasha Shkaran
  • 1,433
  • 2
  • 23
  • 41

2 Answers2

3
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);

This is included in documentation of retrofit.

Ajinkya
  • 1,029
  • 7
  • 15
0

Add Retrofit 2 dependency to 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'

Initialize Retrofit:

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();

Create Retrofit services, such as:

import retrofit2.Call;
import retrofit2.http.GET;

public interface ProfileService {

    @GET("profile")
    Call<User> get();
}

I used @GET("profile") and finally url was: http://your_url/profile

You maybe try change Observable<Profile> to Call<Profile> and delete .json from @GET("profiles.json")