本文介绍了使用Imgur API的Retrofit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在Imgur的API中使用Retrofit库但没有成功。我一直收到403 Permission Denied错误。 Imgur用于我正在尝试做的唯一授权是通过标题,我(我相信)我正在做的。我目前的代码如下:
I'm attempting to use the Retrofit library with Imgur's API with no success. I keep receiving 403 Permission Denied errors. The only authorization Imgur uses for what I'm attempting to do is through a header, which I (believe) I am doing correctly. My current code is the following:
package me.rabrg.imgur;
import me.rabrg.imgur.response.Image;
import me.rabrg.imgur.service.ImageService;
import retrofit.RequestInterceptor;
import retrofit.RestAdapter;
public class ImgurApi {
private final RestAdapter restAdapter;
private final ImageService imageService;
public ImgurApi(final String clientId) {
this.restAdapter = new RestAdapter.Builder().setEndpoint("https://api.imgur.com/3").setRequestInterceptor(new RequestInterceptor() {
@Override
public void intercept(final RequestFacade request) {
request.addHeader("Authorization", "Client-ID " + clientId);
}
}).build();
this.imageService = restAdapter.create(ImageService.class);
}
public Image getImage(final String id) {
return imageService.getImage(id);
}
}
package me.rabrg.imgur.service;
import me.rabrg.imgur.response.Image;
import retrofit.http.POST;
import retrofit.http.Path;
public interface ImageService {
@POST("/image/{id}")
Image getImage(@Path("id") String id);
}
new ImgurApi(clientId).getImage(id)
推荐答案
哈哈,傻我......
Haha, silly me...
方法 getImage
的注释 @POST(/ image / {id})
而不是 @GET(/ image / {id})
这篇关于使用Imgur API的Retrofit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!