J'essaie d'interroger des photos FlickR et recevoir une réponse JSON. J'utilise Retrofit pour faire l'appel à l'API FlickR. Dans mon code, l'utilisateur saisit du texte, qui est capturé via un EditText. Je veux interroger en fonction de ce terme. Je reçois l'erreur suivante de Flick: "Les recherches sans paramètre ont été désactivées. Veuillez utiliser flickr.photos.getRecent à la place."Rechercher des photos FlickR par étiquette
public class MainActivity extends AppCompatActivity {
private EditText mSearchTerm;
private Button mRequestButton;
private String mQuery;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSearchTerm = (EditText) findViewById(R.id.ediText_search_term);
mRequestButton = (Button) findViewById(R.id.request_button);
mRequestButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mQuery = mSearchTerm.getText().toString();
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.flickr.com/services/rest/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build();
ApiInterface apiInterface = retrofit.create(ApiInterface.class);
Call<List<Photo>> call = apiInterface.getPhotos(mQuery);
call.enqueue(new Callback<List<Photo>>() {
@Override
public void onResponse(Call<List<Photo>> call, Response<List<Photo>> response) {
}
@Override
public void onFailure(Call<List<Photo>> call, Throwable t) {
}
});
}
});
}
//Synchronous vs. Asynchronous
public interface ApiInterface {
@GET("?&method=flickr.photos.search&api_key=1c448390199c03a6f2d436c40defd90e&format=json") //
Call<List<Photo>> getPhotos(@Query("q") String photoSearchTerm);
}
}
Avez-vous recherché la documentation API Flickr? – RudolphEst