{"id":17176121,"url":"https://github.com/upbit/pixivapi_ios","last_synced_at":"2025-09-08T03:44:46.672Z","repository":{"id":20242343,"uuid":"23514748","full_name":"upbit/PixivAPI_iOS","owner":"upbit","description":"Pixiv API for IOS","archived":false,"fork":false,"pushed_at":"2019-01-16T01:19:31.000Z","size":2149,"stargazers_count":26,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"react-native","last_synced_at":"2025-04-13T17:06:50.230Z","etag":null,"topics":["pixiv-api"],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/upbit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-31T14:01:15.000Z","updated_at":"2022-08-09T14:37:32.000Z","dependencies_parsed_at":"2022-07-13T22:03:29.556Z","dependency_job_id":null,"html_url":"https://github.com/upbit/PixivAPI_iOS","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upbit%2FPixivAPI_iOS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upbit%2FPixivAPI_iOS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upbit%2FPixivAPI_iOS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upbit%2FPixivAPI_iOS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/upbit","download_url":"https://codeload.github.com/upbit/PixivAPI_iOS/tar.gz/refs/heads/react-native","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248750073,"owners_count":21155685,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pixiv-api"],"created_at":"2024-10-14T23:59:10.388Z","updated_at":"2025-04-13T17:07:13.079Z","avatar_url":"https://github.com/upbit.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"Pixiv API for iOS\n============\n\nPixiv API for iOS, supported both SAPI and Public-API (with OAuth / Bearer token)\n\n* [2015/04/29] add React Native support\n* [2014/10/19] new NSOperationQueue for async request, add Public-API return Model\n\n## Pixiv API Usage:\n\n1. Simplely drag 'PixivAPI/' to your project (copy if needed);\n2. Add **#import \"PixivAPI/PixivAPI.h\"** to your project;\n3. call **login:** and **SAPI / PAPI** functions for you needed;\n\n## API example\n\nPixiv has two API interface:\n\n1. **SAPI:** [http] spapi.pixiv.net/iphone/\n2. **Public-API:** [https] public-api.secure.pixiv.net/\n\nPublic-API return full json data, but check Authorization/Cookie in HTTPS header. Before use Public-API, you need call **login:** or **set_session:** to set PHPSESSID.\n\n\n### Login\n\nBoth loginIfNeeded: / login: are used to Pixiv OAuth, but loginIfNeeded: auto save/load auth token from NSUserDefaults.\n\u003cspan style=\"color:#F00\"\u003eso I recommend that use loginIfNeeded: when you need login:\u003c/span\u003e\n\n**login** (sync):\n\n```objective-c\n    // sync login\n    [[PixivAPI sharedInstance] loginIfNeeded:username password:password];\n```\n\n**login** (async):\n\n```objective-c\n    // use asyncBlockingQueue: for async request\n    [[PixivAPI sharedInstance] asyncBlockingQueue:^{\n        if ([[PixivAPI sharedInstance] loginIfNeeded:@\"username\" password:@\"password\"]) {\n            NSLog(@\"Login success!\");\n        } else {\n            NSLog(@\"Login failed.\");\n        }\n    }];\n```\n\nFor more information about asyncBlockingQueue, you can read [asyncBlockingQueue: section](https://github.com/upbit/PixivAPI_iOS#asyncblockingqueue)\n\n### SAPI\n\nSAPI return SAPIIllust / NSArray of SAPIIllust, or nil on error:\n\n```objective-c\n/**\n *  每日排行\n *  ranking.php\n *\n *  @param page             [1-n]\n *  @param mode             [day, week, month]\n *  @param content          [all, male, female, original]\n *  @param requireAuth      NO\n *\n *  @return NSArray of SAPIIllust\n */\n- (NSArray *)SAPI_ranking:(NSUInteger)page mode:(NSString *)mode content:(NSString *)content requireAuth:(BOOL)requireAuth;\n\n/**\n *  过去的排行\n *  ranking_log.php\n *\n *  @param Date_Year        2014\n *  @param Date_Month       4\n *  @param Date_Day         15\n *  @param mode             [daily, weekly, monthly, male, female, rookie], r18[daily_r18, weekly_r18, male_r18, female_r18, r18g]\n *  @param page             [1-n]\n *  @param requireAuth      YES - for r18 set\n *\n *  @return NSArray of SAPIIllust\n */\n- (NSArray *)SAPI_ranking_log:(NSUInteger)Date_Year month:(NSUInteger)Date_Month day:(NSUInteger)Date_Day\n                         mode:(NSString *)mode page:(NSUInteger)page requireAuth:(BOOL)requireAuth;\n\n/**\n *  作品信息 (新版本已使用 PAPI_works: 代替)\n *  illust.php\n *\n *  @param illust_id        [id for illust]\n *  @param requireAuth      YES - for r18 result\n *\n *  @return SAPIIllust\n */\n- (SAPIIllust *)SAPI_illust:(NSUInteger)illust_id requireAuth:(BOOL)requireAuth;\n\n/**\n *  用户作品列表\n *  member_illust.php\n *\n *  @param author_id        [id for author]\n *  @param page             [1-n]\n *  @param requireAuth      YES - for r18 result\n *\n *  @return NSArray of SAPIIllust\n */\n- (NSArray *)SAPI_member_illust:(NSUInteger)author_id page:(NSUInteger)page requireAuth:(BOOL)requireAuth;\n\n/**\n *  用户资料 (新版本已使用 PAPI_users: 代替)\n *  user.php\n *\n *  @param user_id          [id for author]\n *  @param requireAuth      NO\n *\n *  @return SAPIIllust(Author)\n */\n- (SAPIIllust *)SAPI_user:(NSUInteger)author_id requireAuth:(BOOL)requireAuth;\n\n/**\n *  用户收藏 (新版本已使用 PAPI_users_favorite_works: 代替)\n *  bookmark.php (Authentication required)\n *\n *  @param author_id        [id for author]\n *  @param page             [1-n]\n *  @param requireAuth      YES - for r18 result\n *\n *  @return NSArray of SAPIIllust\n */\n- (NSArray *)SAPI_bookmark:(NSUInteger)author_id page:(NSUInteger)page requireAuth:(BOOL)requireAuth;\n\n/**\n *  标记书签的用户\n *  illust_bookmarks.php\n *\n *  @param illust_id        [id for illust]\n *  @param page             [1-n]\n *  @param requireAuth      NO\n *\n *  @return NSArray of SAPIIllust(Author)\n */\n- (NSArray *)SAPI_illust_bookmarks:(NSUInteger)illust_id page:(NSUInteger)page requireAuth:(BOOL)requireAuth;\n\n/**\n *  关注\n *  bookmark_user_all.php (Authentication required)\n *\n *  @param author_id [id for author]\n *  @param page      [1-n]\n *\n *  @return NSArray of SAPIIllust(Author)\n */\n- (NSArray *)SAPI_bookmark_user_all:(NSUInteger)author_id page:(NSUInteger)page requireAuth:(BOOL)requireAuth;\n\n/**\n *  好P友\n *  mypixiv_all.php\n *\n *  @param author_id [id for author]\n *  @param page      [1-n]\n *\n *  @return NSArray of SAPIIllust(Author)\n */\n- (NSArray *)SAPI_mypixiv_all:(NSUInteger)author_id page:(NSUInteger)page requireAuth:(BOOL)requireAuth;\n```\n\n### Public API\n\nPAPI return PAPIIllust(PAPIAuthor) / PAPIIllustList models, or nil on error:\n\n```objective-c\n/**\n *  作品详细\n *  works/\u003cillust_id\u003e.json\n *\n *  @return PAPIIllust\n */\n- (PAPIIllust *)PAPI_works:(NSUInteger)illust_id;\n\n/**\n *  用户资料\n *  users/\u003cauthor_id\u003e.json\n *\n *  @return PAPIAuthor\n */\n- (PAPIAuthor *)PAPI_users:(NSUInteger)author_id;\n\n/**\n *  我的订阅\n *  me/feeds.json\n *\n *  @param show_r18         NO - hide r18 illusts\n *\n *  @return PAPIIllustList\n */\n- (PAPIIllustList *)PAPI_me_feeds:(BOOL)show_r18;\n\n/**\n *  用户收藏\n *  users/\u003cauthor_id\u003e/favorite_works.json\n *\n *  @param page             [1-n]\n *  @param publicity        YES - public; NO - private (only auth user)\n *\n *  @return PAPIIllustList\n */\n- (PAPIIllustList *)PAPI_users_favorite_works:(NSUInteger)author_id page:(NSUInteger)page publicity:(BOOL)publicity;\n```\n\n### asyncBlockingQueue\n\n```objective-c\n/**\n *  Async run operation in Queue, and then call onCompletion\n *\n *  @param queuePriority     set 0 for NSOperationQueuePriorityNormal\n *  @param mainOperations    code block for sync(blocking) api\n *  @param onCompletion      completion block on mainQueue\n */\n- (void)asyncBlockingQueue:(void (^)(void))mainOperations;\n- (void)asyncBlockingQueue:(NSOperationQueuePriority)queuePriority operations:(void (^)(void))mainOperations completion:(void (^)(void))onCompletion;\n```\n\nAPI use asyncBlockingQueue: for async request, for example:\n\n```objective-c\n    [[PixivAPI sharedInstance] asyncBlockingQueue:^{\n        NSArray *illusts = [[PixivAPI sharedInstance] SAPI_ranking:1 mode:@\"all\" content:@\"day\" requireAuth:NO];\n\n        // 1 - sync fetch\n        for (SAPIIllust *illust in [illusts subarrayWithRange:NSMakeRange(0, 3)]) {\n            NSLog(@\"(%lu) %@\", (unsigned long)[PixivAPI sharedInstance].operationQueue.operationCount, illust);\n\n            SAPIIllust *author = [[PixivAPI sharedInstance] SAPI_user:illust.authorId requireAuth:NO];\n            NSLog(@\"(%lu) %@\", (unsigned long)[PixivAPI sharedInstance].operationQueue.operationCount, author);\n            NSLog(@\"   fetch %ld complete\", (long)author.authorId);\n        }\n\n        NSLog(@\"1 - sync fetch illust[1,2,3] complete\");\n\n        // 2 - async batch fetch\n        for (SAPIIllust *illust in [illusts subarrayWithRange:NSMakeRange(3, 3)]) {\n            [[PixivAPI sharedInstance] asyncBlockingQueue:^{\n                SAPIIllust *author = [[PixivAPI sharedInstance] SAPI_user:illust.authorId requireAuth:NO];\n                NSLog(@\"(%lu) %@\", (unsigned long)[PixivAPI sharedInstance].operationQueue.operationCount, author);\n                NSLog(@\"   fetch %ld complete\", (long)author.authorId);\n            }];\n        }\n\n        NSLog(@\"2 - async illust[4,5,6] start.\");\n    }];\n```\n\noutput:\n\n```\n21:59:29.788 (1) Illust: [なごみ＠かんこれ(id=10457532)] 龍驤たちとオネエな提督(id=46597437)\n21:59:29.926 (1) Author: なごみ＠かんこれ(id=10457532)\n21:59:29.927   fetch 10457532 complete\n21:59:29.927 (1) Illust: [松竜(id=2159670)] 凛さん(id=46599697)\n21:59:30.060 (1) Author: 松竜(id=2159670)\n21:59:30.060    fetch 2159670 complete\n21:59:30.060 (1) Illust: [柳田史太(id=1774701)] 「私はサポート役だから」とか思ってる系女子(id=46599040)\n21:59:30.202 (1) Author: 柳田史太(id=1774701)\n21:59:30.202    fetch 1774701 complete\n21:59:33.217 1 - sync fetch illust[1,2,3] complete\n21:59:33.217 2 - async illust[4,5,6] start.\n21:59:33.592 (3) Author: ポ～ン（出水ぽすか）(id=33333)\n21:59:33.593    fetch 33333 complete\n21:59:33.593 (3) Author: JaneMere(id=49693)\n21:59:33.593    fetch 49693 complete\n21:59:33.765 (1) Author: ふぉぶ(id=465361)\n21:59:33.765    fetch 465361 complete\n```\n\n_Tips:_ MAX_CONCURRENT_OPERATION_COUNT(2) limit only 2 operations run in queue, so operationCount=1 when \"21:59:33.765 (1) Author: ふぉぶ(id=465361)\" request started.\n\n**Update UI on mainQueue:**\n\nasyncBlockingQueue: run operations on operationQueue, it causing UI update delay. So use **onMainQueue:** when you reloadData for UI:\n\n```objective-c\n    __weak ViewController *weakSelf = self;\n    [[PixivAPI sharedInstance] asyncBlockingQueue:^{\n        NSArray *illusts = [[PixivAPI sharedInstance] SAPI_ranking:page mode:@\"day\" content:@\"all\" requireAuth:NO];\n\n        [[PixivAPI sharedInstance] onMainQueue:^{\n            // update UI here\n            weakSelf.illusts = [weakSelf.illusts arrayByAddingObjectsFromArray:illusts];\n            [weakSelf.tableView reloadData];\n        }];\n    }];\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fupbit%2Fpixivapi_ios","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fupbit%2Fpixivapi_ios","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fupbit%2Fpixivapi_ios/lists"}