public class Instagram
A set of helper functions to make the Instagram API easier to use.
-
Starts an authentication process.
Shows a custom
UIViewController
with Intagram’s login page.Note
More information about the login permissions (scope) here.
Declaration
Swift
public func login(navController: UINavigationController, authScope: String = "basic", redirectURI: String, success: EmptySuccessHandler? = nil, failure: FailureHandler? = nil)
Parameters
navController
Your current
UINavigationController
.authScope
The scope of the access you are requesting from the user. Basic access by default.
redirectURI
Your Instagram API client redirection URI.
success
The callback called after a correct login.
failure
The callback called after an incorrect login.
-
Returns whether a session is currently available or not.
Declaration
Swift
public func isSessionValid() -> Bool
Return Value
True if a session is currently available, false otherwise.
-
Ends the current session.
Declaration
Swift
public func logout() -> Bool
Return Value
True if the user was successfully logged out, false otherwise.
-
Get information about a user.
Important
It requires public_content scope when getting information about a user other than yours.
Note
Use
"self"
in theuserId
parameter in order to get information about your own user.Declaration
Swift
public func user(_ userId: String, success: SuccessHandler<InstagramUser>? = nil, failure: FailureHandler? = nil)
Parameters
userId
User identifier or
"self"
.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.
Note
Use
self
in the userId parameter in order to get the most recent media published by your own user.Declaration
Swift
public func recentMedia(fromUser userId: String, maxId: String = "", minId: String = "", count: Int = 0, success: SuccessHandler<[InstagramMedia]>? = nil, failure: FailureHandler? = nil)
Parameters
userId
User identifier.
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 your own user.
Important
It requires public_content scope.
Declaration
Swift
public func userLikedMedia(maxLikeId: String = "", count: Int = 0, success: SuccessHandler<[InstagramMedia]>? = nil, failure: FailureHandler? = nil)
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 = 0, success: SuccessHandler<[InstagramUser]>? = nil, failure: FailureHandler? = nil)
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.
-
Get the list of users this user follows.
Important
It requires follower_list scope.
Declaration
Swift
public func userFollows(success: SuccessHandler<[InstagramUser]>? = nil, failure: FailureHandler? = nil)
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]>? = nil, failure: FailureHandler? = nil)
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]>? = nil, failure: FailureHandler? = nil)
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>? = nil, failure: FailureHandler? = nil)
Parameters
userId
User identifier.
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>? = nil, failure: FailureHandler? = nil)
Parameters
userId
User identifier.
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>? = nil, failure: FailureHandler? = nil)
Parameters
userId
User identifier.
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>? = nil, failure: FailureHandler? = nil)
Parameters
userId
User identifier.
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>? = nil, failure: FailureHandler? = nil)
Parameters
userId
User identifier.
success
The callback called after a correct ignore.
failure
The callback called after an incorrect ignore.
-
Get information about a media object.
Important
It requires public_content scope.
Declaration
Swift
public func media(withId id: String, success: SuccessHandler<InstagramMedia>? = nil, failure: FailureHandler? = nil)
Parameters
id
Media identifier.
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>? = nil, failure: FailureHandler? = nil)
Parameters
shortcode
Media shortcode.
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(lat: Double = 0, lng: Double = 0, distance: Int = 0, success: SuccessHandler<[InstagramMedia]>? = nil, failure: FailureHandler? = nil)
Parameters
lat
Latitude of the center search coordinate. If used,
lng
is required.lng
Longitude of the center search coordinate. If used,
lat
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.
-
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]>? = nil, failure: FailureHandler? = nil)
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, failure: FailureHandler? = nil)
Parameters
mediaId
Media identifier.
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, failure: FailureHandler? = nil)
Parameters
commentId
Comment identifier.
mediaId
Media identifier.
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]>? = nil, failure: FailureHandler? = nil)
Parameters
mediaId
Media identifier.
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, failure: FailureHandler? = nil)
Parameters
mediaId
Media identifier.
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, failure: FailureHandler? = nil)
Parameters
failure
The callback called after an incorrect deletion.
-
Get information about a tag object.
Important
It requires public_content scope.
Declaration
Swift
public func tag(_ tagName: String, success: SuccessHandler<InstagramTag>? = nil, failure: FailureHandler? = nil)
Parameters
tagName
Tag name.
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 = "", minTagId: String = "", count: Int = 0, success: SuccessHandler<[InstagramMedia]>? = nil, failure: FailureHandler? = nil)
Parameters
tagName
Tag name.
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]>? = nil, failure: FailureHandler? = nil)
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 location.
Important
It requires public_content scope.
Declaration
Swift
public func location(_ locationId: String, success: SuccessHandler<InstagramLocation>? = nil, failure: FailureHandler? = nil)
Parameters
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 = "", minId: String = "", success: SuccessHandler<[InstagramMedia]>? = nil, failure: FailureHandler? = nil)
Parameters
locationId
Location identifier.
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(lat: Double = 0, lng: Double = 0, distance: Int = 0, facebookPlacesId: String = "", success: SuccessHandler<[InstagramLocation]>? = nil, failure: FailureHandler? = nil)
Parameters
lat
Latitude of the center search coordinate. If used,
lng
is required.lng
Longitude of the center search coordinate. If used,
lat
is required.distance
Default is 500m, max distance is 750.
facebookPlacesId
Returns a location mapped off of a Facebook places id. If used,
lat
andlng
are not required.success
The callback called after a correct retrieval.
failure
The callback called after an incorrect retrieval.