在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:shyambhat/InstagramKit开源软件地址:https://github.com/shyambhat/InstagramKit开源编程语言:Objective-C 98.9%开源软件介绍:InstagramKitAn extensive Objective C wrapper for the Instagram API, completely compatible with Swift. Here's a quick example to retrieve trending media on Instagram: InstagramEngine *engine = [InstagramEngine sharedEngine];
[engine getPopularMediaWithSuccess:^(NSArray *media, InstagramPaginationInfo *paginationInfo) {
// media is an array of InstagramMedia objects
...
} failure:^(NSError *error, NSInteger statusCode) {
...
}]; The framework is built atop AFNetworking’s blocks-based architecture and additionally, parses JSON data and creates model objects asynchronously so there’s absolutely no parsing on the main thread. It’s neat, fast and works like a charm. ExampleTo run the example project, clone the repo, and run InstallationInstagramKit is available through CocoaPods. To install it, simply add the following line to your Podfile: pod 'InstagramKit' If your App uses authorization and you'd like the storage and retrieval of the access token in the Keychain to be automatically handled for you by UICKeyChainStore, include the following lines instead - pod 'InstagramKit'
pod 'InstagramKit/UICKeyChainStore' InstagramKit uses UICKeyChainStore as an optional sub-dependency for Keychain access. If you opt to use the optional pod, InstagramKit resumes your authenticated sessions across App launches, without needing any additional code. Instagram Developer RegistrationHead over to http://instagram.com/developer/clients/manage/ to register your app with Instagram and set the right credentials for
Instagram Platform UpdatesInstagram frequently updates its APIs and deprecates endpoints that are in use. If you see a 400 or other strange errors from the server response, please check on Instagram's API changelog and create an issue with your findings. https://www.instagram.com/developer/changelog/ UsageAuthenticationFor each API call, you will need an Access Token and specific scope permissions. To get the Access Token, the user needs to authenticate your app to access his Instagram account with the specified permissions. To do so, redirect the user to NSURL *authURL = [[InstagramEngine sharedEngine] authorizationURL];
[self.webView loadRequest:[NSURLRequest requestWithURL:authURL]]; ScopesAll apps have basic read access by default, but if you plan on asking for extended access such as liking, commenting, or managing friendships, you need to specify these scopes in your authorization request using the InstagramKitScope enum. Note that in order to use these extended permissions, first you need to submit your app for review to Instagram. For your app to POST or DELETE likes, comments or follows, you must apply to Instagram here : https://www.facebook.com/help/instagram/contact/185819881608116# // Set scope depending on permissions your App has been granted from Instagram
// InstagramKitLoginScopeBasic is included by default.
InstagramKitLoginScope scope = InstagramKitLoginScopeRelationships | InstagramKitLoginScopeComments | InstagramKitLoginScopeLikes;
NSURL *authURL = [[InstagramEngine sharedEngine] authorizationURLForScope:scope];
[self.webView loadRequest:[NSURLRequest requestWithURL:authURL]]; Once the user grants your app permission, they will be redirected to a url in the form of something like UIWebView- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSError *error;
if ([[InstagramEngine sharedEngine] receivedValidAccessTokenFromURL:request.URL error:&error]) {
// success!
...
}
return YES;
} WKWebView- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(nonnull WKNavigationAction *)navigationAction decisionHandler:(nonnull void (^)(WKNavigationActionPolicy))decisionHandler
{
NSError *error;
if ([[InstagramEngine sharedEngine] receivedValidAccessTokenFromURL:navigationAction.request.URL error:&error]) {
// success!
...
}
decisionHandler(WKNavigationActionPolicyAllow);
}
Authenticated RequestsOnce you're authenticated and InstagramKit has been provided an InstagramEngine *engine = [InstagramEngine sharedEngine];
[engine getSelfRecentMediaWithSuccess:^(NSArray *media, InstagramPaginationInfo *paginationInfo) {
// media is an array of InstagramMedia objects
...
} failure:^(NSError *error, NSInteger statusCode) {
...
}]; PaginationThe If you need to make fetch a paginated feed of results, use the variation of the method which accepts [engine getMediaForUser:user.Id
count:15
maxId:self.currentPaginationInfo.nextMaxId
withSuccess:^(NSArray *media, InstagramPaginationInfo *paginationInfo)
{
if (paginationInfo) {
self.currentPaginationInfo = paginationInfo;
}
...
}
failure:^(NSError *error)
{
...
}]; The first request will go with Each endpoint in the Instagram API that supports pagination, usually supports a count parameter. You can use this method and pass a count parameter to each paginated request. You can also use it in cases where you do not need pagination, but need to specify a feed count to the first request. Read in detail about more ways of implementing Pagination for your requests effortlessly in the Pagination Wiki. Contributions?Glad you asked. Check out the open Issues and jump right in. Questions?The Instagram API Documentation is your definitive source of information in case something goes wrong. Please make sure you've read up the documentation before posting issues. AuthorShyam Bhat, [email protected] Twitter: @bhatthead LicenseInstagramKit is available under the MIT license. See the LICENSE file for more info. ================== InstagramKit uses the public Instagram API and is not affiliated with either Instagram or Facebook. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论