Gramophone is a framework for interacting with the Instagram REST API, written in Swift.
It includes authentication via OAuth, and methods to make asynchronous network calls to all of Instagram's publicly available API endpoints.
Responses are parsed into concrete model objects and errors.
Setup the client, supplying your Instagram client id and redirect URI, as well as any desired scopes:
import Gramophone
let configuration = ClientConfiguration(
clientID: "{YOUR_INSTAGRAM_CLIENT_ID}",
redirectURI: "{YOUR_INSTAGRAM_REDIRECT_URI}",
scopes: [.basic, .publicContent, .comments]
)
let gramophone = Gramophone(configuration: configuration)
Authenticate using OAuth (with an in-app WKWebView
controller):
gramophone.client.authenticate(from: presentingViewController) { result in
switch result {
case .success(let response):
print("Authenticated")
case .failure(let error):
print("Failed to authenticate: \(error.localizedDescription)")
}
}
Request data using one of the API wrapper methods:
gramophone.client.myRecentMedia(options: nil) { mediaResult in
switch mediaResult {
case .success(let response):
let mediaItems = response.data.items
for media in mediaItems {
if let images = media.images, let rendition = images[.thumbnail] {
print("Media [ID: \(media.ID), url: \(rendition.url)]")
}
}
case .failure(let error):
print("Failed to load media: \(error.localizedDescription)")
}
}
See the Resources directory for the full listing of available API methods:
API Wrapper | Methods | Instagram Docs |
---|---|---|
Auth |
|
Docs |
Comments |
|
Docs |
Likes |
|
Docs |
Locations |
|
Docs |
Media |
|
Docs |
OEmbed |
|
Docs |
Relationships |
|
Docs |
Tags |
|
Docs |
Users |
|
Docs |
To integrate Gramophone using CocoaPods, add it to your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target '{YOUR_TARGET}' do
pod 'Gramophone', '~> 1.1'
end
Then, run:
$ pod install
To integrate Gramophone using Carthage, add it to your Cartfile
:
github "jverdi/Gramophone" ~> 1.1
Then, run:
$ carthage update --platform iOS
and drag the built Gramophone.framework
, Decodable.framework
, and Result.framework
into your Xcode project's Embedded Binaries from Carthage/Build/iOS
.
Gramophone makes use of the Decodable and Result libraries.
Gramophone is released under the MIT license. See LICENSE for details.
Icon created by Gan Khoon Lay from the Noun Project