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インタフェース写真参照およびキー
@GET("photo")
Call<ResponseBody> getSinglePhoto(@Query("maxwidth") Integer maxwidth, @Query("photoreference") String photoreference, @Query("key") String key);
// APIクライアント
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;
}
//ベースURL
の助けを借りて改装ライブラリを使用してボディ応じて写真を取得public static final String BASE_URL_PHOTO = "https://maps.googleapis.com/maps/api/place/";
私は試していますこのコードはgですが、私は応答本体で何も取得できません。ボディは常にnullです。写真参照を使用して写真を取得する方法はありますか?グライドは、私がここにコードを掲示していますあなたのため正常に動作していると
はアドバンス
デベロッパーコンソールでプレイスAPIが有効になっていることを確認してください。画像をダウンロードするにはGlide/Picassoを使用してください。 –
@MuraliPrajapatiはい、プレイスAPIはデベロッパーコンソールで有効になっています。私はピカソをダウンロードに使用しています。しかし、応答本体にはヌル値が含まれていました。サンプルコードを取得する場合は、また良い。ありがとうございました!! –
私は郵便配達員でこのapiを試してみました。 https://developers.google.com/places/web-service/photos –