Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

callAPIMethod:withParameters:success:failure: Request failed: unauthorized (401) #167

Open
ghost opened this issue Sep 25, 2015 · 2 comments

Comments

@ghost
Copy link

ghost commented Sep 25, 2015

I wrote an app that allowed the user to search for a song in Rdio. I'm calling the API method called "search" and everything was working fine. However today I tried the same code (without any changes at all) and now I'm getting the following error:

Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: unauthorized (401)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x12e5afd70> { URL: https://services.rdio.com/api/1/search } { status code: 401, headers {
    "Access-Control-Allow-Origin" = "*";
    "Access-Control-Expose-Headers" = "x-rdio-api-version";
    "Cache-Control" = "no-cache";
    Connection = "keep-alive";
    "Content-Language" = "es-mx";
    "Content-Length" = 82;
    "Content-Type" = "application/json";
    Date = "Fri, 25 Sep 2015 19:00:43 GMT";
    P3P = "CP=\"This is not a P3P policy. See http://www.rdio.com/legal/privacy-policy for more info.\"";
    Server = "nginx/1.2.4";
    Vary = "Accept-Language, Cookie";
    "X-Version" = 720;
    "X-srv" = "srv-108-16";
} }, NSErrorFailingURLKey=https://services.rdio.com/api/1/search, com.alamofire.serialization.response.error.data=<7b226572 726f725f 64657363 72697074 696f6e22 3a202249 6e76616c 6964206f 72206578 70697265 64206163 63657373 20746f6b 656e222c 20226572 726f7222 3a202269 6e76616c 69645f74 6f6b656e 227d>, NSLocalizedDescription=Request failed: unauthorized (401)}

If I translate the error response data I get the following:
{"error_description": "Invalid or expired access token", "error": "invalid_token"}

I don't understand why I'm getting this error if, according to the documentation, this API method "Does not require user authentication."

@dasevilla
Copy link
Contributor

All API methods require an access token. There are two types of access tokens: with or without a user. For methods labeled "Does not require user authentication" you can use the Client Credentials Grant to generate an access token without a user.

Once you've generated an access token it will expire within 12-hours. After it has expired, you need to use a refresh token or use the Client Credentials Grant to generate a new access token.

@Pugintv
Copy link

Pugintv commented Oct 7, 2015

@dasevilla Will this work with the new SDK update released?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants