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 **)errorParameters
- artistUris
An array of
NSURLs for artists to check.
- accessToken
An authenticated access token. Must be valid and authorized with the
user-follow-modifyscope.
- error
An optional pointer to a
NSErrorthat 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.hcreateRequestForCheckingIfFollowingUsers: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 **)errorParameters
- username
A
NSStrings containing spotify username to check.
- accessToken
An authenticated access token. Must be valid and authorized with the
user-follow-modifyscope.
- error
An optional pointer to a
NSErrorthat 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.hcreateRequestForCheckingIfUsers: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 **)errorParameters
- usernames
A list of spotify usernames.
- playlistUri
A playlist URI.
- accessToken
An authenticated access token. Must be valid and authorized with the
user-follow-modifyscope.
- error
An optional pointer to a
NSErrorthat 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.hcreateRequestForFollowingArtists:withAccessToken:error:
Create a request for making the current user follow a list of artist.
+ (NSURLRequest *)createRequestForFollowingArtists:(NSArray *)artistUris withAccessToken:(NSString *)accessToken error:(NSError **)errorParameters
- artistUris
An array of
NSURLs for artist to follow.
- accessToken
An authenticated access token. Must be valid and authorized with the
user-follow-modifyscope.
- error
An optional pointer to a
NSErrorthat 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.hcreateRequestForFollowingPlaylist:withAccessToken:secret:error:
Create a request for following a playlist.
+ (NSURLRequest *)createRequestForFollowingPlaylist:(NSURL *)playlistUri withAccessToken:(NSString *)accessToken secret:(BOOL)secret error:(NSError **)errorParameters
- playlistUri
The playlist URI to follow.
- accessToken
An authenticated access token. Must be valid and authorized with the
playlist-modify-privateorplaylist-modify-publicscope depending on if you’re following it publicly or not.
- secret
Follow this playlist secretly.
- error
An optional pointer to a
NSErrorthat 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.hcreateRequestForFollowingUsers:withAccessToken:error:
Create a request to make the current user follow a list of users.
+ (NSURLRequest *)createRequestForFollowingUsers:(NSArray *)usernames withAccessToken:(NSString *)accessToken error:(NSError **)errorParameters
- usernames
An array of
NSStrings containing spotify usernames to follow.
- accessToken
An authenticated access token. Must be valid and authorized with the
user-follow-modifyscope.
- error
An optional pointer to a
NSErrorthat 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.hcreateRequestForUnfollowingArtists:withAccessToken:error:
Create a request for making the current user unfollow a list of artists.
+ (NSURLRequest *)createRequestForUnfollowingArtists:(NSArray *)artistUris withAccessToken:(NSString *)accessToken error:(NSError **)errorParameters
- artistUris
An array of
NSURLs for artists to unfollow.
- accessToken
An authenticated access token. Must be valid and authorized with the
user-follow-modifyscope.
- error
An optional pointer to a
NSErrorthat 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.hcreateRequestForUnfollowingPlaylist:withAccessToken:error:
Create a request to check if a user is following a specific playlist.
+ (NSURLRequest *)createRequestForUnfollowingPlaylist:(NSURL *)playlistUri withAccessToken:(NSString *)accessToken error:(NSError **)errorParameters
- playlistUri
A playlist URI.
- accessToken
An authenticated access token. Must be valid and authorized with the
user-follow-modifyscope.
- error
An optional pointer to a
NSErrorthat 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.hcreateRequestForUnfollowingUsers:withAccessToken:error:
Create a request to make the current user unfollow a list of users.
+ (NSURLRequest *)createRequestForUnfollowingUsers:(NSArray *)usernames withAccessToken:(NSString *)accessToken error:(NSError **)errorParameters
- usernames
An array of
NSStrings containing spotify usernames to unfollow.
- accessToken
An authenticated access token. Must be valid and authorized with the
user-follow-modifyscope.
- error
An optional pointer to a
NSErrorthat 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.hfollowingResultFromData: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 **)errorParameters
- data
The API response data
- response
The API response object
- error
An optional pointer to a
NSErrorthat receives an error if request creation failed.
Return Value
An NSArray of booleans
Declared In
SPTFollow.h