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
UIViewController
with Intagram’s login page.Declaration
Swift
public func login(from controller: UINavigationController, withScopes scopes: [InstagramScope] = [.basic], success: EmptySuccessHandler?, failure: FailureHandler?)
Parameters
controller
The
UINavigationController
from which theInstagramLoginViewController
will be showed.scopes
The scope of the access you are requesting from the user. Basic access by default.
success
The callback called after a correct login.
failure
The callback called after an incorrect login.
-
Ends the current session.
Declaration
Swift
@discardableResult public func logout() -> Bool
Return 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
success
The callback called after a correct retrieval.
failure
The 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
mediaId
The ID of the media object to reference.
text
Text to post as a comment on the media object as specified in
mediaId
.failure
The 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
commentId
The ID of the comment to delete.
mediaId
The ID of the media object to reference.
failure
The 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
mediaId
The ID of the media object to reference.
success
The callback called after a correct retrieval.
failure
The 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
mediaId
The ID of the media object to reference.
failure
The 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
failure
The 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
locationId
The ID of the location to reference.
success
The callback called after a correct retrieval.
failure
The 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
locationId
The ID of the location to reference.
maxId
Return media after this
maxId
.minId
Return media before this
mindId
.success
The callback called after a correct retrieval.
failure
The 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
latitude
Latitude of the center search coordinate. If used,
longitude
is required.longitude
Longitude of the center search coordinate. If used,
latitude
is required.distance
Default is 500m, max distance is 750.
facebookPlacesId
Returns a location mapped off of a Facebook places id. If used,
coordinates
is not required.success
The callback called after a correct retrieval.
failure
The 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
coordinates
Latitude and longitude of the center search coordinates.
distance
Default is 500m, max distance is 750.
facebookPlacesId
Returns a location mapped off of a Facebook places id. If used,
coordinates
is not required.success
The callback called after a correct retrieval.
failure
The 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
id
The ID of the media object to reference.
success
The callback called after a correct retrieval.
failure
The 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
shortcode
The shortcode of the media object to reference.
success
The callback called after a correct retrieval.
failure
The 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
latitude
Latitude of the center search coordinate. If used,
longitude
is required.longitude
Longitude of the center search coordinate. If used,
latitude
is required.distance
Default is 1km (1000m), max distance is 5km.
success
The callback called after a correct retrieval.
failure
The 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
coordinates
Latitude and longitude of the center search coordinates.
distance
Default is 1km (1000m), max distance is 5km.
success
The callback called after a correct retrieval.
failure
The 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
success
The callback called after a correct retrieval.
failure
The 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
success
The callback called after a correct retrieval.
failure
The 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
success
The callback called after a correct retrieval.
failure
The 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
userId
The ID of the user to reference.
success
The callback called after a correct retrieval.
failure
The 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
userId
The ID of the user to reference.
success
The callback called after a correct follow.
failure
The 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
userId
The ID of the user to reference.
success
The callback called after a correct unfollow.
failure
The 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
userId
The ID of the user to reference.
success
The callback called after a correct approve.
failure
The 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
userId
The ID of the user to reference.
success
The callback called after a correct ignore.
failure
The 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
tagName
The name of the tag to reference.
success
The callback called after a correct retrieval.
failure
The 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
tagName
The name of the tag to reference.
maxTagId
Return media after this
maxTagId
.minTagId
Return media before this
minTagId
.count
Count of tagged media to return.
success
The callback called after a correct retrieval.
failure
The 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
query
A valid tag name without a leading #. (eg. snowy, nofilter)
success
The callback called after a correct retrieval.
failure
The 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
userId
The ID of the user whose information to retrieve, or
self
to reference the currently authenticated user.success
The callback called after a correct retrieval.
failure
The 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
userId
The ID of the user whose recent media to retrieve, or
self
to reference the currently authenticated user.maxId
Return media earlier than this
maxId
.minId
Return media later than this
minId
.count
Count of media to return.
success
The callback called after a correct retrieval.
failure
The 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
maxLikeId
Return media liked before this id.
count
Count of media to return.
success
The callback called after a correct retrieval.
failure
The 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
query
A query string.
count
Number of users to return.
success
The callback called after a correct retrieval.
failure
The callback called after an incorrect retrieval.