SPTFollow Class Reference
Inherits from | NSObject |
Declared in | SPTFollow.h |
Overview
This class provides helpers for using the follow features in the Spotify API.
API Docs: https://developer.spotify.com/web-api/web-api-follow-endpoints/
API Console: https://developer.spotify.com/web-api/console/follow/
Example of following a user:
NSURLRequest *req = [SPTFollow createRequestForFollowingUsers:@[@"possan"]] withAccessToken:@"<your accesstoken>" error:nil];
[[SPTRequest sharedHandler] performRequest:req callback:^(NSError *error, NSURLResponse *response, NSData *data) {
long statusCode = ((NSHTTPURLResponse*)response).statusCode;
switch (statusCode) {
case 204:
NSLog(@"Successfully followed user.");
break;
case 401:
case 403:
NSLog(@"Failed to follow user, are you sure your token is valid and have the correct scopes?");
break;
default:
NSLog(@"Unknown error");
break;
}
}];
Example of checking if a user is following a playlist:
NSError *err2 = nil;
NSURLRequest *req2 = [SPTFollow createRequestForCheckingIfUsers:@[@"possan"]
areFollowingPlaylist:[NSURL URLWithString:@"spotify:user:eldloppa:playlist:4irwclB6noltFaHhqZSWRu"]
withAccessToken:auth.session.accessToken
error:&err2];
NSLog(@"created request %@", req2);
[[SPTRequest sharedHandler] performRequest:req2 callback:^(NSError *error, NSURLResponse *response, NSData *data) {
NSLog(@"error=%@, response=%@, data=%@", error, response, data);
NSArray *arr = [SPTFollow followingResultFromData:data withResponse:response error:nil];
NSLog(@"is following? %@", [arr objectAtIndex:0]);
}];
Tasks
API Request Factories
-
+ createRequestForFollowingArtists:withAccessToken:error:
-
+ createRequestForUnfollowingArtists:withAccessToken:error:
-
+ createRequestForCheckingIfFollowingArtists:withAccessToken:error:
-
+ createRequestForFollowingUsers:withAccessToken:error:
-
+ createRequestForUnfollowingUsers:withAccessToken:error:
-
+ createRequestForCheckingIfFollowingUsers:withAccessToken:error:
-
+ createRequestForFollowingPlaylist:withAccessToken:secret:error:
-
+ createRequestForUnfollowingPlaylist:withAccessToken:error:
-
+ createRequestForCheckingIfUsers:areFollowingPlaylist:withAccessToken:error:
API Response Parsers
Class Methods
createRequestForCheckingIfFollowingArtists:withAccessToken:error:
Create a request to check if the current user is following a list of artists.
+ (NSURLRequest *)createRequestForCheckingIfFollowingArtists:(NSArray *)artistUris withAccessToken:(NSString *)accessToken error:(NSError **)error
Parameters
- artistUris
An array of
NSURL
s for artists to check.
- accessToken
An authenticated access token. Must be valid and authorized with the
user-follow-modify
scope.
- error
An optional pointer to a
NSError
that receives an error if request creation failed.
Return Value
The created NSURLRequest
.
Discussion
Parse the response in to an NSArray
of booleans using parseFollowingResultData:withResponse:error
See https://developer.spotify.com/web-api/check-current-user-follows/ for more information on parameters
Declared In
SPTFollow.h
createRequestForCheckingIfFollowingUsers:withAccessToken:error:
Create a request to check if the current user is following a list of users.
+ (NSURLRequest *)createRequestForCheckingIfFollowingUsers:(NSArray *)username withAccessToken:(NSString *)accessToken error:(NSError **)error
Parameters
- username
A
NSString
s containing spotify username to check.
- accessToken
An authenticated access token. Must be valid and authorized with the
user-follow-modify
scope.
- error
An optional pointer to a
NSError
that receives an error if request creation failed.
Return Value
The created NSURLRequest
.
Discussion
Parse the response in to an NSArray
of booleans using parseFollowingResultData:withResponse:error
See https://developer.spotify.com/web-api/check-current-user-follows/ for more information on parameters
Declared In
SPTFollow.h
createRequestForCheckingIfUsers:areFollowingPlaylist:withAccessToken:error:
Create a request to check if a user is following a specific playlist.
+ (NSURLRequest *)createRequestForCheckingIfUsers:(NSArray *)usernames areFollowingPlaylist:(NSURL *)playlistUri withAccessToken:(NSString *)accessToken error:(NSError **)error
Parameters
- usernames
A list of spotify usernames.
- playlistUri
A playlist URI.
- accessToken
An authenticated access token. Must be valid and authorized with the
user-follow-modify
scope.
- error
An optional pointer to a
NSError
that receives an error if request creation failed.
Return Value
The created NSURLRequest
.
Discussion
Parse the response in to an NSArray
of booleans using SPTFollow parseFollowingResultData:withResponse:error
See https://developer.spotify.com/web-api/get-list-new-releases/ for more information on parameters
Declared In
SPTFollow.h
createRequestForFollowingArtists:withAccessToken:error:
Create a request for making the current user follow a list of artist.
+ (NSURLRequest *)createRequestForFollowingArtists:(NSArray *)artistUris withAccessToken:(NSString *)accessToken error:(NSError **)error
Parameters
- artistUris
An array of
NSURL
s for artist to follow.
- accessToken
An authenticated access token. Must be valid and authorized with the
user-follow-modify
scope.
- error
An optional pointer to a
NSError
that receives an error if request creation failed.
Return Value
The created NSURLRequest
.
Discussion
See https://developer.spotify.com/web-api/follow-artists-users/ for more information on parameters
Declared In
SPTFollow.h
createRequestForFollowingPlaylist:withAccessToken:secret:error:
Create a request for following a playlist.
+ (NSURLRequest *)createRequestForFollowingPlaylist:(NSURL *)playlistUri withAccessToken:(NSString *)accessToken secret:(BOOL)secret error:(NSError **)error
Parameters
- playlistUri
The playlist URI to follow.
- accessToken
An authenticated access token. Must be valid and authorized with the
playlist-modify-private
orplaylist-modify-public
scope depending on if you’re following it publicly or not.
- secret
Follow this playlist secretly.
- error
An optional pointer to a
NSError
that receives an error if request creation failed.
Return Value
The created NSURLRequest
.
Discussion
See https://developer.spotify.com/web-api/get-list-new-releases/ for more information on parameters
Declared In
SPTFollow.h
createRequestForFollowingUsers:withAccessToken:error:
Create a request to make the current user follow a list of users.
+ (NSURLRequest *)createRequestForFollowingUsers:(NSArray *)usernames withAccessToken:(NSString *)accessToken error:(NSError **)error
Parameters
- usernames
An array of
NSString
s containing spotify usernames to follow.
- accessToken
An authenticated access token. Must be valid and authorized with the
user-follow-modify
scope.
- error
An optional pointer to a
NSError
that receives an error if request creation failed.
Return Value
The created NSURLRequest
.
Discussion
See https://developer.spotify.com/web-api/follow-artists-users/ for more information on parameters
Declared In
SPTFollow.h
createRequestForUnfollowingArtists:withAccessToken:error:
Create a request for making the current user unfollow a list of artists.
+ (NSURLRequest *)createRequestForUnfollowingArtists:(NSArray *)artistUris withAccessToken:(NSString *)accessToken error:(NSError **)error
Parameters
- artistUris
An array of
NSURL
s for artists to unfollow.
- accessToken
An authenticated access token. Must be valid and authorized with the
user-follow-modify
scope.
- error
An optional pointer to a
NSError
that receives an error if request creation failed.
Return Value
The created NSURLRequest
.
Discussion
See https://developer.spotify.com/web-api/unfollow-artists-users/ for more information on parameters
Declared In
SPTFollow.h
createRequestForUnfollowingPlaylist:withAccessToken:error:
Create a request to check if a user is following a specific playlist.
+ (NSURLRequest *)createRequestForUnfollowingPlaylist:(NSURL *)playlistUri withAccessToken:(NSString *)accessToken error:(NSError **)error
Parameters
- playlistUri
A playlist URI.
- accessToken
An authenticated access token. Must be valid and authorized with the
user-follow-modify
scope.
- error
An optional pointer to a
NSError
that receives an error if request creation failed.
Return Value
The created NSURLRequest
.
Discussion
See https://developer.spotify.com/web-api/get-list-new-releases/ for more information on parameters
Declared In
SPTFollow.h
createRequestForUnfollowingUsers:withAccessToken:error:
Create a request to make the current user unfollow a list of users.
+ (NSURLRequest *)createRequestForUnfollowingUsers:(NSArray *)usernames withAccessToken:(NSString *)accessToken error:(NSError **)error
Parameters
- usernames
An array of
NSString
s containing spotify usernames to unfollow.
- accessToken
An authenticated access token. Must be valid and authorized with the
user-follow-modify
scope.
- error
An optional pointer to a
NSError
that receives an error if request creation failed.
Return Value
The created NSURLRequest
.
Discussion
See https://developer.spotify.com/web-api/unfollow-artists-users/ for more information on parameters
Declared In
SPTFollow.h
followingResultFromData:withResponse:error:
Parse the result of a “am i following this entity”-query into an array of booleans
+ (NSArray *)followingResultFromData:(NSData *)data withResponse:(NSURLResponse *)response error:(NSError **)error
Parameters
- data
The API response data
- response
The API response object
- error
An optional pointer to a
NSError
that receives an error if request creation failed.
Return Value
An NSArray
of booleans
Declared In
SPTFollow.h