[英]Unauthorized error while trying to intercept Retrofit request
I am using Retrofit below 2.0 in order to make API call. 我正在2.0以下使用Retrofit以便进行API调用。 The endpoint is " http://api.themoviedb.org/3 ".
端点是“ http://api.themoviedb.org/3 ”。 The method is
方法是
@GET("/discover/movie")
void getMovies(Callback<MoviesResponse> callback);
They want me to add api_key as parameter. 他们要我添加api_key作为参数。 You can see the instructions here .
您可以在此处查看说明。
I am creating interceptor and setting it while building the client. 我在创建客户端时创建拦截器并对其进行设置。 This is the overridden method of the interceptor.
这是拦截器的替代方法。
@Override
public void intercept(RequestFacade request) {
request.addHeader("api_key", MY_API_KEY);
}
For some reason I get Unauthorized error. 出于某种原因,我收到未经授权的错误。 "Invalid API key: You must be granted a valid key."
“无效的API密钥:您必须被授予有效的密钥。”
The example they are giving is: 他们给出的示例是:
http://api.themoviedb.org/3/movie/550?api_key=###
I found what was wrong. 我发现出了什么问题。 I was adding a header while they were asking for parameter.
我在请求参数时添加了标头。
@Override
public void intercept(RequestFacade request) {
request.addQueryParam(HEADER_NAME, mApiKey);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.