Help us understand the problem. What is going on with this article?

AFNetworking で Qiita API を操作

More than 5 years have passed since last update.

原文: http://snippets.feb19.jp/?p=1300

Qiita API に言及した記事なのでこちらにもぺたり

-

AFNetworking

http://afnetworking.com

AFNetworking とは Objective-C 周りでのめんどくさい WebAPI 操作やデータアップロード・ダウンロードをシンプルにしてくれるライブラリ。

Qiita API を例にして Web API 操作を行ってみます。

Qiita API

インストール

Podfile からインストール

platform :ios, '7.0'
pod "AFNetworking", "~> 2.0"

宣言

#import <AFNetworking/AFNetworking.h>

GET: Qiita の特定ユーザーの情報を取得する

https://qiita.com/docs#5

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"https://qiita.com/api/v1/users/ユーザー名" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
    NSLog(@"Website URL: %@", [responseObject objectForKey:@"website_url"]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

POST: Qiita API を操作する token の取得

https://qiita.com/docs#3

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *params = @{@"url_name": @"ユーザー名",
                         @"password": @"パスワード"};
[manager POST:@"https://qiita.com/api/v1/auth" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
    NSLog(@"Token: %@", [responseObject objectForKey:@"token"]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];
feb19
Designer / Engineer http://feb19.jp
http://feb19.jp/blog
dena_coltd
    Delight and Impact the World
https://dena.com/jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした