简体   繁体   English

尝试拦截改造请求时出现未经授权的错误

[英]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.

相关问题 尝试从Twitter API获取Oauth request_token时出现“未经授权”错误 - Getting “Unauthorized” Error while trying to get Oauth request_token from twitter API 在改造中获得401未经授权的错误? - Getting 401 unauthorized error in retrofit? 构建请求时出现Android Retrofit错误 - Android Retrofit error while building a request 获取401错误在发出肥皂请求时未经授权 - Getting 401 error Unauthorized while making soap request 在改造调用的标头中设置授权令牌后出现未经授权的错误 - Getting unauthorized error after setting the authorization token in the header of retrofit call 获取意外的JDWP错误:103尝试使用改造上传图像到api服务器android? - Getting a Unexpected JDWP Error: 103 while trying to upload an image using retrofit to an api server android? 云端点返回错误401未经授权的请求 - cloud endpoints return error 401 unauthorized request Retrofit 错误请求错误:如何做 Retrofit POST 正确的方式 - Retrofit Bad Request Error: How to do Retrofit POST the right way 尝试使用ErrorDocument处理请求时遇到404 Not Found错误 - 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request 改装后请求:500个内部服务器错误 - Retrofit post request: 500 internal server error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM