Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

api,Get Recently Played Tracks

api,Get Recently Played Tracks

 

Device

(iPhone 13)

Operating System

iOS

 

 

Hello,

I am using the Authorization Code Flow to obtain a token and trying to make a request to get recently played tracks (Get Recently Played Tracks). However, I am encountering a 403 error.

The first time I made this request, it succeeded and I was able to retrieve the recently played tracks

The response body indicates: "Check settings on developer.spotify.com/dashboard, the user may not be registered."

Could you please assist me in resolving this issue?

Thank you.

Reply
6 Replies

Hi jasperjarecki, welcome back to the Community!

Are you trying to use it with your developer account or another?

And could you please add a code block with your code, so I can help you find the bug?

You can insert a code block by first clicking on …, and then on </>.

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

enum SearchMusicAPI {
    case searchMusic(byName: String, limit: Int, type: String, offset: Int)
    case getRecently(limit: Int)
}

extension SearchMusicAPI: TargetType {
    enum Parameters {
      
        static let limit = "limit"
       
    }
        
    var baseURL: URL {
        guard let url = Constants.API.baseURL else { fatalError() }
        return url
    }
    
    var path: String {
        switch self {
        
        case .getRecently: return "/v1/me/player/recently-played"
        }
    }
    
    var method: Moya.Method { .get }
    
    var sampleData: Data { return "".data(using: .utf8)! }
    
    var headers: [String: String]? {
        switch self {
        case .getRecently:
            return ["Authorization" : "Bearer " + (UserDefaults.standard.string(forKey: "token") ?? ""),
                    "Content-Type" : "application/json",
                    "Accept" : "application/json"]
        }
    }
        
    var task: Task {
        switch self {
      
        case let .getRecently(limit):
            return .requestParameters(parameters: [Parameters.limit : limit],
                                      encoding: URLEncoding.default)
        }
    }
}

I am adding code with the token retrieval service, but the code keeps getting deleted.

Hi jasperjarecki, thanks for posting your code.

I don't see how you acquired the Bearer token. I think there is a mistake in the step of getting it.

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Снимок экрана 2024-07-24 в 14.58.49.png

Снимок экрана 2024-07-24 в 14.58.56.png

Снимок экрана 2024-07-24 в 14.58.39.png

   

That is inconvenient that it keeps getting deleted. Thank you providing screenshots anyway.
I don't see any obvious bugs. As you noticed the first time running your code, it worked.
Does the Bearer token get stored anywhere at your machine? And do you test this app with your developer account, or another?

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Suggested posts