1
String photoReference = imageDataObject.getPhotoReference();
String width = imageDataObject.getWidth();
String height = imageDataObject.getHeight();
ApiInterface apiServicePhoto = ApiClient.getClient(GlobalConstant.BASE_URL_PHOTO).create(ApiInterface.class);
Call<ResponseBody> callPhoto = apiServicePhoto.getSinglePhoto(GlobalConstant.MAX_WIDTH_IMAGE, photoReference, GlobalConstant.API_KEY);
callPhoto.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Log.e(TAG, "onResponse: " + response);
if (response.isSuccessful()) {
if (response.body() != null) {
Log.e(TAG, "onResponse: ");
}
Log.e(TAG, "onResponse: " + response.body());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.e(TAG, "onFailure: ");
}
});
// API-SchnittstelleFetch Foto in Körperantwort Retrofit-Bibliothek mit Hilfe von Foto-Referenz und Schlüssel
@GET("photo")
Call<ResponseBody> getSinglePhoto(@Query("maxwidth") Integer maxwidth, @Query("photoreference") String photoreference, @Query("key") String key);
// API Client
public class ApiClient {
private static Retrofit retrofit = null;
public static Retrofit getClient(String baseUrlRestro) {
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(baseUrlRestro)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
// Basis-URL
public static final String BASE_URL_PHOTO = "https://maps.googleapis.com/maps/api/place/";
Ich bin tryin g diesen Code, aber ich kann nichts in Antwort Körper bekommen. Körper immer null. Gibt es eine Möglichkeit, ein Foto mit einem Foto-Verweis zu erhalten?
Vielen Dank im Voraus
Stellen Sie sicher, dass die Stellen-API in der Entwicklerkonsole aktiviert ist. oder verwenden Sie Glide/Picasso zum Herunterladen von Bildern –
@MuraliPrajapati Ja, Place-API ist in der Entwicklerkonsole aktiviert. Ich benutze Picasso zum Herunterladen. Der Antworttext enthielt jedoch einen Nullwert. Wenn Sie einen Beispielcode bekommen, dann auch gut. Danke!! –
Ich habe versucht, diese API im Postboten es funktioniert gut dort. Verwende die von Google gegebene Photoreferenz hier: https: //developers.google.com/places/web-service/photos –