SKCurrentUser
public struct SKCurrentUser : User, JSONDecodable
The current authenticated Spotify user.
See also
The Web API Private User object.-
Declaration
Swift
public let displayName: String? -
Declaration
Swift
public let externalURLs: [String : URL] -
Declaration
Swift
public let followers: SKFollowers? -
Declaration
Swift
public let id: String -
Declaration
Swift
public let images: [SKImage]? -
Declaration
Swift
public let uri: String -
Declaration
Swift
public let url: URL
-
The user’s date-of-birth.
Note
This field is only available when the current user has granted access to theuser-read-birthdatescope. See Authorization Scopes for more details.Declaration
Swift
public let birthdate: Date? -
The country of the user, as set in the user’s account profile. This value returns an ISO 3166-1 alpha-2 country code.
Note
This field is only available when the current user has granted access to theuser-read-privatescope. See Authorization Scopes for more details.Declaration
Swift
public let country: String? -
The user’s email address, as entered by the user when creating their account.
Important
This email address is unverified; there is no proof that it actually belongs to the user.Note
This field is only available when the current user has granted access to theuser-read-emailscope. See Authorization Scopes for more details.Declaration
Swift
public let email: String? -
The user’s Spotify subscription level:
premium
,free
, etc. (The subscription levelopen
can be considered the same asfree
.)Note
This field is only available when the current user has granted access to theuser-read-privatescope. See Authorization Scopes for more details.Declaration
Swift
public let product: ProductType?
-
Declaration
Swift
public init(from jsonData: Data) throws
-
Gets detailed profile information about the current authenticated user.
Note
This method uses theSPTAuthdefault instance session to authenticate the underlying request. If this session does not contain a valid access token, the request will result in an error. The access token must have been issued on behalf of the current user.To retrieve all user properties, the access token also must have been generated with certain scopes authorized. In particular:
- Reading the user’s email address requires the
user-read-emailscope. - Reading the user’s country and product subscription level requires the
user-read-privatescope. - Reading the user’s date of birth requires the
user-read-birthdatescope.
See Using Scopes for more details.
Declaration
Swift
public static func getCurrentUser(completion handler: @escaping (SKCurrentUser?, Error?) -> Void)Parameters
idThe user’s Spotify user ID.
handlerThe callback handler for the request. The parameters for this handler are:
user: The current authenticated user, if available.error: An error identifying if and why the request failed, ornilif the request was successful.
- Reading the user’s email address requires the
-
Creates and returns the request used to get the current authenticated user’s playlists.
Declaration
Swift
public func makePlaylistsRequest(page: Pagination?) -> SKRequestParameters
pageThe parameters for paginating the results, specifying the index and number of items to return. If no parameters are supplied, the request will return the default number of items beginning with first item.
Return Value
An
SKRequestinstance with which to perform the API request. -
Gets a list of the playlists owned or followed by the current authenticated user.
Note
This method uses theSPTAuthdefault instance session to authenticate the underlying request. If this session does not contain a valid access token, the request will result in an error. The access token must have been issued on behalf of the current user.Private playlists are only retrievable for the current user and requires the
playlist-read-privatescope to have been authorized by the user. Note that this scope alone will not return collaborative playlists, even though they are always private.See Using Scopes for more details.
Declaration
Swift
public func getPlaylists(page: Pagination? = nil, completion handler: @escaping (Page<SKPlaylist>?, Error?) -> Void)Parameters
pageThe parameters for paginating the results, specifying the index and number of items to return. If no parameters are supplied, the request will return the default number of items beginning with first item. The default value is
nil.handlerThe callback handler for the request. The parameters for this handler are:
user: The current authenticated user, if available.error: An error identifying if and why the request failed, ornilif the request was successful.
-
Creates and returns the request used to get the current authenticated user’s followed artists.
Declaration
Swift
public static func makeFollowedArtistsRequest(lastID: String?, limit: Int?) -> SKRequestParameters
lastIDThe last artist’s ID in the previous page, if any. Providing an artist ID for this request is similar to providing an offset value in other paginated requests.
limitThe number of items to return.
Return Value
An
SKRequestinstance with which to perform the API request. -
Gets the current authenticated user’s followed artists.
Note
This method uses theSPTAuthdefault instance session to authenticate the underlying request. If this session does not contain a valid access token, the request will result in an error. The access token must have been issued on behalf of the current user.Reading the list of items that the current authenticated user follows also requires authorization of the
user-follow-readscope. See Using Scopes for more details.Declaration
Swift
public static func getFollowedArtists(afterID lastID: String? = nil, limit: Int? = nil, completion handler: @escaping (CursorPage<SKArtist>?, Error?) -> Void)Parameters
lastIDThe last artist’s ID in the previous page, if any. Providing an artist ID for this request is similar to providing an offset value in other paginated requests. The default value is
nil.limitThe number of items to return. The default value is
nil.handlerThe callback handler for the request. The parameters for this handler are:
artists: A cursor-based paginated list of followed artists, if any.error: An error identifying if and why the request failed, ornilif the request was successful.
-
Creates and returns the request used to get the current authenticated user’s saved albums.
Declaration
Swift
public static func makeSavedAlbumsRequest(locale: Locale?, page: Pagination?) -> SKRequestParameters
localeThe locale-specific storefront/market from which to request.
pageThe parameters for paginating the results, specifying the index and number of items to return. If no parameters are supplied, the request will return the default number of items beginning with first item.
Return Value
An
SKRequestinstance with which to perform the API request. -
Gets the list of albums saved in the current authenticated user’s Spotify music library.
Note
This method uses theSPTAuthdefault instance session to authenticate the underlying request. If this session does not contain a valid access token, the request will result in an error. The access token must have been issued on behalf of the current user.Reading the current user’s
Your Music
collection requires authorization of theuser-library-readscope. See Using Scopes for more details.Declaration
Swift
public static func getSavedAlbums(for locale: Locale? = SKCatalog.local.locale, page: Pagination? = nil, completion handler: @escaping (Page<SKSavedAlbum>?, Error?) -> Void)Parameters
localeThe locale-specific storefront/market from which to request. The default value is the locale for the shared
SKCataloginstance, which by default represents the user’s region settings at the time the method is called.pageThe parameters for paginating the results, specifying the index and number of items to return. If no parameters are supplied, the request will return the default number of items beginning with first item. The default value is
nil.handlerThe callback handler for the request. The parameters for this handler are:
albums: A paginated collection of saved albums, if available.error: An error identifying if and why the request failed, ornilif the request was successful.
-
Creates and returns the request used to get the current authenticated user’s saved tracks.
Declaration
Swift
public static func makeSavedTracksRequest(locale: Locale?, page: Pagination?) -> SKRequestParameters
localeThe locale-specific storefront/market from which to request.
pageThe parameters for paginating the results, specifying the index and number of items to return. If no parameters are supplied, the request will return the default number of items beginning with first item.
Return Value
An
SKRequestinstance with which to perform the API request. -
Gets the list of tracks saved in the current authenticated user’s Spotify music library.
Note
This method uses theSPTAuthdefault instance session to authenticate the underlying request. If this session does not contain a valid access token, the request will result in an error. The access token must have been issued on behalf of the current user.Reading the current user’s
Your Music
collection requires authorization of theuser-library-readscope. See Using Scopes for more details.Declaration
Swift
public static func getSavedTracks(for locale: Locale? = SKCatalog.local.locale, page: Pagination? = nil, completion handler: @escaping (Page<SKSavedTrack>?, Error?) -> Void)Parameters
localeThe locale-specific storefront/market from which to request. The default value is the locale for the shared
SKCataloginstance, which by default represents the user’s region settings at the time the method is called.pageThe parameters for paginating the results, specifying the index and number of items to return. If no parameters are supplied, the request will return the default number of items beginning with first item. The default value is
nil.handlerThe callback handler for the request. The parameters for this handler are:
tracks: A paginated collection of saved tracks, if available.error: An error identifying if and why the request failed, ornilif the request was successful.
-
Creates and returns the request used to get the current authenticated user’s top artists.
Declaration
Swift
public static func makeTopArtistsRequest(range: SKTimeRange, page: Pagination?) -> SKRequestParameters
rangeThe time frame across which affinities are computed. Possible values are
.lastFourWeeks,.lastSixMonths, and.beginningOfTime, which spans several years of data including all new data as it becomes available.pageThe parameters for paginating the results, specifying the index and number of items to return. If no parameters are supplied, the request will return the default number of items beginning with first item.
Return Value
An
SKRequestinstance with which to perform the API request. -
Gets a list of the current authenticated user’s top artists.
Remark
Top artists are based on calculated affinity. Affinity is a measure of the expected preference a user has for a particular track or artist. It is based on user behavior, including play history, but does not include actions made while in incognito mode. Light or infrequent users of Spotify may not have sufficient play history to generate a full affinity data set.
Note
This method uses the
SPTAuthdefault instance session to authenticate the underlying request. If this session does not contain a valid access token, the request will result in an error. The access token must have been issued on behalf of the current user.Reading the current user’s top artists or tracks requires authorization of the
user-top-readscope. See Using Scopes for more details.Declaration
Swift
public static func getTopArtists(from range: SKTimeRange = .lastSixMonths, page: Pagination? = nil, completion handler: @escaping (Page<SKArtist>?, Error?) -> Void)Parameters
rangeThe time frame across which affinities are computed. Possible values are
.lastFourWeeks,.lastSixMonths, and.beginningOfTime, which spans several years of data including all new data as it becomes available. The default value is.lastSixMonths.pageThe parameters for paginating the results, specifying the index and number of items to return. If no parameters are supplied, the request will return the default number of items beginning with first item. The default value is
nil.handlerThe callback handler for the request. The parameters for this handler are:
artists: A paginated collection of up to 50 artists, if available.error: An error identifying if and why the request failed, ornilif the request was successful.
-
Creates and returns the request used to get the current authenticated user’s top tracks.
Declaration
Swift
public static func makeTopTracksRequest(range: SKTimeRange, page: Pagination?) -> SKRequestParameters
rangeThe time frame across which affinities are computed. Possible values are
.lastFourWeeks,.lastSixMonths, and.beginningOfTime, which spans several years of data including all new data as it becomes available.pageThe parameters for paginating the results, specifying the index and number of items to return. If no parameters are supplied, the request will return the default number of items beginning with first item.
Return Value
An
SKRequestinstance with which to perform the API request. -
Gets a list of the current authenticated user’s top tracks.
Remark
Top artists are based on calculated affinity. Affinity is a measure of the expected preference a user has for a particular track or artist. It is based on user behavior, including play history, but does not include actions made while in incognito mode. Light or infrequent users of Spotify may not have sufficient play history to generate a full affinity data set.
Note
This method uses the
SPTAuthdefault instance session to authenticate the underlying request. If this session does not contain a valid access token, the request will result in an error. The access token must have been issued on behalf of the current user.Reading the current user’s top artists or tracks requires authorization of the
user-top-readscope. See Using Scopes for more details.Declaration
Swift
public static func getTopTracks(from range: SKTimeRange = .lastSixMonths, page: Pagination? = nil, completion handler: @escaping (Page<SKTrack>?, Error?) -> Void)Parameters
rangeThe time frame across which affinities are computed. Possible values are
.lastFourWeeks,.lastSixMonths, and.beginningOfTime, which spans several years of data including all new data as it becomes available. The default value is.lastSixMonths.pageThe parameters for paginating the results, specifying the index and number of items to return. If no parameters are supplied, the request will return the default number of items beginning with first item. The default value is
nil.handlerThe callback handler for the request. The parameters for this handler are:
tracks: A paginated collection of up to 50 tracks, if available.error: An error identifying if and why the request failed, ornilif the request was successful.
View on GitHub
SKCurrentUser Structure Reference