{"id":38,"date":"2014-04-21T20:00:43","date_gmt":"2014-04-21T11:00:43","guid":{"rendered":"http:\/\/fankey.info\/blog\/?p=38"},"modified":"2014-04-22T16:49:41","modified_gmt":"2014-04-22T07:49:41","slug":"obj-c-%e3%83%81%e3%83%a3%e3%83%83%e3%83%88%e3%83%af%e3%83%bc%e3%82%afapi%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b","status":"publish","type":"post","link":"http:\/\/blog.fankey.info\/?p=38","title":{"rendered":"\u3010Obj-C\u3011 \u30c1\u30e3\u30c3\u30c8\u30ef\u30fc\u30afAPI\u3092\u4f7f\u3063\u3066\u307f\u308b"},"content":{"rendered":"<p><a href=\"http:\/\/www.chatwork.com\/ja\/\" target=\"_blank\">\u30c1\u30e3\u30c3\u30c8\u30ef\u30fc\u30af<\/a>\u3068\u306f\u3001\u30af\u30e9\u30a6\u30c9\u578b\u306e\u30d3\u30b8\u30cd\u30b9\u30c1\u30e3\u30c3\u30c8\u30c4\u30fc\u30eb\u3067\u3059\u3002<br \/>\n\u8077\u5834\u3067\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30b3\u30df\u30e5\u30cb\u30b1\u30fc\u30b7\u30e7\u30f3\u30c4\u30fc\u30eb\u3068\u3057\u3066\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u304b\u306a\u308a\u4f7f\u3044\u3084\u3059\u304f\u3066\u3001\u6c17\u306b\u5165\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u73fe\u5728\u3001\u30c1\u30e3\u30c3\u30c8\u30ef\u30fc\u30afAPI\u306e\u30d7\u30ec\u30d3\u30e5\u30fc\u7248\u304c\u516c\u958b\u3055\u308c\u3066\u3044\u3066\u3001\u7533\u8acb\u3092\u3059\u308c\u3070\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\u8a73\u3057\u304f\u306f<a href=\"http:\/\/developer.chatwork.com\/ja\/\" target=\"_blank\">\u3053\u3061\u3089<\/a>\u304b\u3089\u3002<br \/>\n\u516c\u958b\u3055\u308c\u3066\u3059\u3050\u306b\u7533\u3057\u8fbc\u3093\u3067\u306f\u3044\u305f\u306e\u3067\u3059\u304c\u3001\u5168\u304f\u624b\u3092\u4ed8\u3051\u3066\u3044\u307e\u305b\u3093\u3067\u3057\u305f\u306e\u3067\u7c21\u5358\u306bObjective-C\u3067\u4f7f\u3063\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\nHTTP\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u6295\u3052\u308b\u3068\u3001Json\u5f62\u5f0f\u3067\u7d50\u679c\u304c\u8fd4\u3063\u3066\u304d\u307e\u3059\u3002\u305d\u308c\u3092\u3061\u3087\u3061\u3087\u3044\u3068\u51e6\u7406\u3059\u308b\u3060\u3051\u3067\u7c21\u5358\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u51fa\u6765\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>[objc]<\/p>\n<p>NSString * const EndPointBase = @&quot;https:\/\/api.chatwork.com\/v1\/&quot;;<br \/>\nNSString * const Token = @&quot;\u81ea\u5206\u306e\u30c8\u30fc\u30af\u30f3&quot;;<\/p>\n<p>-(void)getMeInfo<br \/>\n{<br \/>\n    NSString *EndPointPath = @&quot;me&quot;;<br \/>\n    NSURL *base = [NSURL URLWithString:EndPointBase];<br \/>\n    NSURL *url = [NSURL URLWithString:EndPointPath relativeToURL:base];<br \/>\n    NSMutableURLRequest *request = [self createRequest:url];<\/p>\n<p>    \/\/ \u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1\u3059\u308b\uff08\u540c\u671f\u901a\u4fe1\uff09<br \/>\n    NSError *error;<br \/>\n    NSURLResponse *response;<br \/>\n    NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error];<\/p>\n<p>    \/\/ NSData \u2192 Json\u306b\u5909\u63db<br \/>\n    id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];<br \/>\n    NSLog(@&quot;%@&quot;, obj);<br \/>\n}<\/p>\n<p>-(NSMutableURLRequest *)createRequest:(NSURL *)url<br \/>\n{<br \/>\n    NSMutableURLRequest *request;<br \/>\n    request = [[NSMutableURLRequest alloc] init];<br \/>\n    [request setURL:url];<br \/>\n    [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];<br \/>\n    [request setTimeoutInterval:20];<br \/>\n    [request addValue:Token forHTTPHeaderField:@&quot;X-ChatWorkToken&quot;];<br \/>\n    [request setHTTPShouldHandleCookies:FALSE];<\/p>\n<p>    return request;<br \/>\n}<br \/>\n[\/objc]<\/p>\n<p>\u3053\u3093\u306a\u611f\u3058\u3067\u66f8\u3044\u3066\u307f\u305f\u3089\u3001NSLog\u3067\u30ec\u30b9\u30dd\u30f3\u30b9\u306eJson\u304c\u51fa\u529b\u3055\u308c\u307e\u3057\u305f\u3002<br \/>\n\u73fe\u5728\u306fAPI\u30c8\u30fc\u30af\u30f3\u3092\u4f7f\u7528\u3057\u305f\u8a8d\u8a3c\u3057\u304b\u51fa\u6765\u306a\u3044\u306e\u3067\u3001\u3060\u308c\u3067\u3082\u4f7f\u3048\u308b\u3088\u3046\u306a\u30a2\u30d7\u30ea\u306e\u958b\u767a\u306f\u96e3\u3057\u305d\u3046\u3067\u3059\u304c\u3001\u4eca\u5f8c\u3001<strong>OAuth 2.0\u306b\u3088\u308b\u8a8d\u8a3c\u65b9\u5f0f\u3092\u63d0\u4f9b\u4e88\u5b9a<\/strong>\u3089\u3057\u3044\u306e\u3067\u305d\u308c\u304c\u51fa\u6765\u308c\u3070\u3055\u3089\u306b\u5e45\u304c\u5e83\u304c\u308a\u305d\u3046\u3067\u3059\u306d\u3002<\/p>\n<p>\u6b21\u306f\u3001iBeacon\u3092\u4f7f\u7528\u3057\u3066\u3001\u4f1a\u793e\u306b\u30d3\u30fc\u30b3\u30f3\u7aef\u672b\u3092\u7f6e\u3044\u3066\u304a\u3044\u3066\u3001\u51fa\u793e\u3057\u305f\u3089\u30c1\u30e3\u30c3\u30c8\u30ef\u30fc\u30af\u306e\u81ea\u5206\u306e\u672a\u5b8c\u4e86\u30bf\u30b9\u30af\u3092\u901a\u77e5\u3059\u308biPhone\u30a2\u30d7\u30ea\u3092\u4f5c\u3063\u3066\u307f\u3088\u3046\u304b\u3068\u601d\u3063\u3066\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30c1\u30e3\u30c3\u30c8\u30ef\u30fc\u30af\u3068\u306f\u3001\u30af\u30e9\u30a6\u30c9\u578b\u306e\u30d3\u30b8\u30cd\u30b9\u30c1\u30e3\u30c3\u30c8\u30c4\u30fc\u30eb\u3067\u3059\u3002 \u8077\u5834\u3067\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30b3\u30df\u30e5\u30cb\u30b1\u30fc\u30b7\u30e7\u30f3\u30c4\u30fc\u30eb\u3068\u3057\u3066\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u304b\u306a\u308a\u4f7f\u3044\u3084\u3059\u304f\u3066\u3001\u6c17\u306b\u5165\u3063\u3066\u3044\u307e\u3059\u3002 \u73fe\u5728\u3001\u30c1\u30e3\u30c3\u30c8\u30ef\u30fc\u30afAPI\u306e &#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-38","post","type-post","status-publish","format-standard","hentry","category-tech"],"_links":{"self":[{"href":"http:\/\/blog.fankey.info\/index.php?rest_route=\/wp\/v2\/posts\/38","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.fankey.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.fankey.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.fankey.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.fankey.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=38"}],"version-history":[{"count":10,"href":"http:\/\/blog.fankey.info\/index.php?rest_route=\/wp\/v2\/posts\/38\/revisions"}],"predecessor-version":[{"id":55,"href":"http:\/\/blog.fankey.info\/index.php?rest_route=\/wp\/v2\/posts\/38\/revisions\/55"}],"wp:attachment":[{"href":"http:\/\/blog.fankey.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=38"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.fankey.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=38"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.fankey.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=38"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}