public class Instagram
A set of helper functions to make the Instagram API easier to use.
-
Empty success handler.
Declaration
Swift
public typealias EmptySuccessHandler = () -> Void -
Success handler.
Declaration
Swift
public typealias SuccessHandler<T> = (_ data: T) -> Void -
Failure handler.
Declaration
Swift
public typealias FailureHandler = (_ error: Error) -> Void
-
Returns a shared instance of Instagram.
Declaration
Swift
public static let shared: Instagram
-
Starts an authentication process.
Shows a custom
UIViewControllerwith Intagram’s login page.Declaration
Swift
public func login(from controller: UINavigationController, withScopes scopes: [InstagramScope] = [.basic], success: EmptySuccessHandler?, failure: FailureHandler?)Parameters
controllerThe
UINavigationControllerfrom which theInstagramLoginViewControllerwill be showed.scopesThe scope of the access you are requesting from the user. Basic access by default.
successThe callback called after a correct login.
failureThe callback called after an incorrect login.
-
Ends the current session.
Declaration
Swift
@discardableResult public func logout() -> BoolReturn Value
True if the user was successfully logged out, false otherwise.
-
Returns whether a user is currently authenticated or not.
Declaration
Swift
public var isAuthenticated: Bool { get }
-
Store your own authenticated access token so you don’t have to use the included login authentication.
Declaration
Swift
public func storeAccessToken(_ accessToken: String) -> Bool -
Returns the current access token.
Declaration
Swift
public func retrieveAccessToken() -> String?
-
Get a list of recent comments on a media object.
Important
It requires public_content scope for media that does not belong to your own user.
Declaration
Swift
public func comments(fromMedia mediaId: String, success: SuccessHandler<[InstagramComment]>?, failure: FailureHandler?)Parameters
successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Create a comment on a media object.
Important
It requires comments scope. Also, public_content scope is required for media that does not belong to your own user.
Note
note:
- The total length of the comment cannot exceed 300 characters.
- The comment cannot contain more than 4 hashtags.
- The comment cannot contain more than 1 URL.
- The comment cannot consist of all capital letters.
Declaration
Swift
public func createComment(onMedia mediaId: String, text: String, success: SuccessHandler<InstagramComment>?, failure: FailureHandler?)Parameters
mediaIdThe ID of the media object to reference.
textText to post as a comment on the media object as specified in
mediaId.failureThe callback called after an incorrect creation.
-
Remove a comment either on the authenticated user’s media object or authored by the authenticated user.
Important
It requires comments scope. Also, public_content scope is required for media that does not belong to your own user.
Declaration
Swift
public func deleteComment(_ commentId: String, onMedia mediaId: String, success: EmptySuccessHandler?, failure: FailureHandler?)Parameters
commentIdThe ID of the comment to delete.
mediaIdThe ID of the media object to reference.
failureThe callback called after an incorrect deletion.
-
Get a list of users who have liked this media.
Important
It requires public_content scope for media that does not belong to your own user.
Declaration
Swift
public func likes(inMedia mediaId: String, success: SuccessHandler<[InstagramUser]>?, failure: FailureHandler?)Parameters
mediaIdThe ID of the media object to reference.
successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Set a like on this media by the currently authenticated user.
Important
It requires likes scope. Also, public_content scope is required for media that does not belong to your own user.
Declaration
Swift
public func like(media mediaId: String, success: EmptySuccessHandler?, failure: FailureHandler?)Parameters
mediaIdThe ID of the media object to reference.
failureThe callback called after an incorrect like.
-
Remove a like on this media by the currently authenticated user.
Important
It requires likes scope. Also, public_content scope is required for media that does not belong to your own user.
Declaration
Swift
public func unlike(media mediaId: String, success: EmptySuccessHandler?, failure: FailureHandler?)Parameters
failureThe callback called after an incorrect deletion.
-
Get information about a location.
Important
It requires public_content scope.
Declaration
Swift
public func location(_ locationId: String, success: SuccessHandler<InstagramLocation<String>>?, failure: FailureHandler?)Parameters
locationIdThe ID of the location to reference.
successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Get a list of recent media objects from a given location.
Important
It requires public_content scope.
Declaration
Swift
public func recentMedia(forLocation locationId: String, maxId: String? = nil, minId: String? = nil, success: SuccessHandler<[InstagramMedia]>?, failure: FailureHandler?)Parameters
locationIdThe ID of the location to reference.
maxIdReturn media after this
maxId.minIdReturn media before this
mindId.successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Search for a location by geographic coordinate.
Important
It requires public_content scope.
Declaration
Swift
public func searchLocation(latitude: Double? = nil, longitude: Double? = nil, distance: Int? = nil, facebookPlacesId: String? = nil, success: SuccessHandler<[InstagramLocation<String>]>?, failure: FailureHandler?)Parameters
latitudeLatitude of the center search coordinate. If used,
longitudeis required.longitudeLongitude of the center search coordinate. If used,
latitudeis required.distanceDefault is 500m, max distance is 750.
facebookPlacesIdReturns a location mapped off of a Facebook places id. If used,
coordinatesis not required.successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Search for a location by geographic coordinate.
Important
It requires public_content scope.
Declaration
Swift
public func searchLocation(coordinates: CLLocationCoordinate2D? = nil, distance: Int? = nil, facebookPlacesId: String? = nil, success: SuccessHandler<[InstagramLocation<String>]>?, failure: FailureHandler?)Parameters
coordinatesLatitude and longitude of the center search coordinates.
distanceDefault is 500m, max distance is 750.
facebookPlacesIdReturns a location mapped off of a Facebook places id. If used,
coordinatesis not required.successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Get information about a media object.
Important
It requires public_content scope.
Declaration
Swift
public func media(withId id: String, success: SuccessHandler<InstagramMedia>?, failure: FailureHandler?)Parameters
idThe ID of the media object to reference.
successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Get information about a media object.
Important
It requires public_content scope.
Note
A media object’s shortcode can be found in its shortlink URL. An example shortlink is http://instagram.com/p/tsxp1hhQTG/. Its corresponding shortcode is tsxp1hhQTG.
Declaration
Swift
public func media(withShortcode shortcode: String, success: SuccessHandler<InstagramMedia>?, failure: FailureHandler?)Parameters
shortcodeThe shortcode of the media object to reference.
successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Search for recent media in a given area.
Important
It requires public_content scope.
Declaration
Swift
public func searchMedia(latitude: Double? = nil, longitude: Double? = nil, distance: Int? = nil, success: SuccessHandler<[InstagramMedia]>?, failure: FailureHandler?)Parameters
latitudeLatitude of the center search coordinate. If used,
longitudeis required.longitudeLongitude of the center search coordinate. If used,
latitudeis required.distanceDefault is 1km (1000m), max distance is 5km.
successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Search for recent media in a given area.
Important
It requires public_content scope.
Declaration
Swift
public func searchMedia(coordinates: CLLocationCoordinate2D? = nil, distance: Int? = nil, success: SuccessHandler<[InstagramMedia]>?, failure: FailureHandler?)Parameters
coordinatesLatitude and longitude of the center search coordinates.
distanceDefault is 1km (1000m), max distance is 5km.
successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Get the list of users this user follows.
Important
It requires follower_list scope.
Declaration
Swift
public func userFollows(success: SuccessHandler<[InstagramUser]>?, failure: FailureHandler?)Parameters
successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Get the list of users this user is followed by.
Important
It requires follower_list scope.
Declaration
Swift
public func userFollowers(success: SuccessHandler<[InstagramUser]>?, failure: FailureHandler?)Parameters
successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
List the users who have requested this user’s permission to follow.
Important
It requires follower_list scope.
Declaration
Swift
public func userRequestedBy(success: SuccessHandler<[InstagramUser]>?, failure: FailureHandler?)Parameters
successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Get information about a relationship to another user.
Important
It requires follower_list scope.
Declaration
Swift
public func userRelationship(withUser userId: String, success: SuccessHandler<InstagramRelationship>?, failure: FailureHandler?)Parameters
userIdThe ID of the user to reference.
successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Follows the target user.
Important
It requires relationships scope.
Declaration
Swift
public func follow(user userId: String, success: SuccessHandler<InstagramRelationship>?, failure: FailureHandler?)Parameters
userIdThe ID of the user to reference.
successThe callback called after a correct follow.
failureThe callback called after an incorrect follow.
-
Unfollows the target user.
Important
It requires relationships scope.
Declaration
Swift
public func unfollow(user userId: String, success: SuccessHandler<InstagramRelationship>?, failure: FailureHandler?)Parameters
userIdThe ID of the user to reference.
successThe callback called after a correct unfollow.
failureThe callback called after an incorrect unfollow.
-
Approve the target user’s request.
Important
It requires relationships scope.
Declaration
Swift
public func approveRequest(fromUser userId: String, success: SuccessHandler<InstagramRelationship>?, failure: FailureHandler?)Parameters
userIdThe ID of the user to reference.
successThe callback called after a correct approve.
failureThe callback called after an incorrect approve.
-
Ignore the target user’s request.
Important
It requires relationships scope.
Declaration
Swift
public func ignoreRequest(fromUser userId: String, success: SuccessHandler<InstagramRelationship>?, failure: FailureHandler?)Parameters
userIdThe ID of the user to reference.
successThe callback called after a correct ignore.
failureThe callback called after an incorrect ignore.
-
Get information about a tag object.
Important
It requires public_content scope.
Declaration
Swift
public func tag(_ tagName: String, success: SuccessHandler<InstagramTag>?, failure: FailureHandler?)Parameters
tagNameThe name of the tag to reference.
successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Get a list of recently tagged media.
Important
It requires public_content scope.
Declaration
Swift
public func recentMedia(withTag tagName: String, maxTagId: String? = nil, minTagId: String? = nil, count: Int? = nil, success: SuccessHandler<[InstagramMedia]>?, failure: FailureHandler?)Parameters
tagNameThe name of the tag to reference.
maxTagIdReturn media after this
maxTagId.minTagIdReturn media before this
minTagId.countCount of tagged media to return.
successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Search for tags by name.
Important
It requires public_content scope.
Declaration
Swift
public func search(tag query: String, success: SuccessHandler<[InstagramTag]>?, failure: FailureHandler?)Parameters
queryA valid tag name without a leading #. (eg. snowy, nofilter)
successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Get information about a user.
Important
It requires public_content scope when getting information about a user other than yours.
Declaration
Swift
public func user(_ userId: String, success: SuccessHandler<InstagramUser>?, failure: FailureHandler?)Parameters
userIdThe ID of the user whose information to retrieve, or
self
to reference the currently authenticated user.successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Get the most recent media published by a user.
Important
It requires public_content scope when getting recent media published by a user other than yours.
Declaration
Swift
public func recentMedia(fromUser userId: String, maxId: String? = nil, minId: String? = nil, count: Int? = nil, success: SuccessHandler<[InstagramMedia]>?, failure: FailureHandler?)Parameters
userIdThe ID of the user whose recent media to retrieve, or
self
to reference the currently authenticated user.maxIdReturn media earlier than this
maxId.minIdReturn media later than this
minId.countCount of media to return.
successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Get the list of recent media liked by the currently authenticated user.
Important
It requires public_content scope.
Declaration
Swift
public func userLikedMedia(maxLikeId: String? = nil, count: Int? = nil, success: SuccessHandler<[InstagramMedia]>?, failure: FailureHandler?)Parameters
maxLikeIdReturn media liked before this id.
countCount of media to return.
successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
-
Get a list of users matching the query.
Important
It requires public_content scope.
Declaration
Swift
public func search(user query: String, count: Int? = nil, success: SuccessHandler<[InstagramUser]>?, failure: FailureHandler?)Parameters
queryA query string.
countNumber of users to return.
successThe callback called after a correct retrieval.
failureThe callback called after an incorrect retrieval.
View on GitHub
Instagram Class Reference