{"id":4086,"date":"2010-09-29T23:39:51","date_gmt":"2010-09-29T14:39:51","guid":{"rendered":"http:\/\/ke-tai.org\/blog\/?p=4086"},"modified":"2010-09-29T23:43:29","modified_gmt":"2010-09-29T14:43:29","slug":"opensocialput","status":"publish","type":"post","link":"http:\/\/ke-tai.org\/blog\/2010\/09\/29\/opensocialput\/","title":{"rendered":"Opensocial\u306eRESTfulAPI\u3067PUT\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u30b5\u30f3\u30d7\u30eb"},"content":{"rendered":"<p>\u6628\u65e5\u306b\u5f15\u304d\u7d9a\u304dOpensocial\u30cd\u30bf\u3067\u3059\u3002<\/p>\n<p>\u30bd\u30fc\u30b7\u30e3\u30eb\u30b2\u30fc\u30e0\u306a\u3069\u3092\u4f5c\u6210\u3059\u308b\u969b\u306bOpensocial\u306eRESTfulAPI\u3092\u4f7f\u3046\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>GET\u3084POST\u306e\u60c5\u5831\u306f\u3001\u691c\u7d22\u3059\u308b\u3068\u305d\u308c\u306a\u308a\u306b\u51fa\u3066\u304d\u307e\u3059\u3057\u3001\u30b5\u30a4\u30c8\u4e0a\u306b\u3082\u30b5\u30f3\u30d7\u30eb\u304c\u3042\u3063\u305f\u308a\u3059\u308b\u306e\u3067\u3059\u304c\u3001PUT\u30e1\u30bd\u30c3\u30c9\u3084DELETE\u30e1\u30bd\u30c3\u30c9\u3067\u306e\u63a5\u7d9a\u3092\u8981\u6c42\u3055\u308c\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u5b58\u5728\u306f\u4f55\u3068\u306a\u304f\u77e5\u3063\u3066\u3044\u305f\u3082\u306e\u306e\u3001\u305d\u3093\u306a\u30e1\u30bd\u30c3\u30c9\u306f\u5f53\u7136\u4f7f\u3063\u305f\u3053\u3068\u306f\u306a\u304f\u3001\u691c\u7d22\u3057\u3066\u3082\u30b5\u30f3\u30d7\u30eb\u3082\u5c11\u306a\u304f\u56f0\u308a\u307e\u3057\u305f\u3002<\/p>\n<p class=\"spacer\">&nbsp;<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u672c\u65e5\u306fOAuth\u7f72\u540d\u4ed8\u304d\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u3067PUT\u30e1\u30bd\u30c3\u30c9\u3092\u9001\u4fe1\u3059\u308b\u30b5\u30f3\u30d7\u30eb\u3092\u516c\u958b\u3057\u3066\u307f\u307e\u3059\u3002<br \/>\n\uff08\u56fd\u5185\u30e2\u30d0\u30a4\u30eb\u5411\u3051\u306e\u30bd\u30fc\u30b7\u30e3\u30eb\u30a2\u30d7\u30ea\u306f\u8272\u3005\u3068\u60c5\u5831\u516c\u958b\u306b\u5236\u9650\u304c\u3042\u308b\u306e\u3067\u3001\u5dee\u3057\u969c\u308a\u306e\u7121\u3044\u7bc4\u56f2\u3067\u307e\u3068\u3081\u307e\u3057\u305f\uff09<\/p>\n<p>\u30b3\u30fc\u30c9\u306f\u3001\u3053\u3061\u3089\u306eOAuth.php\u306b\u4f9d\u5b58\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\nexample\u5185\u306b\u3042\u308b\u30b3\u30fc\u30c9\u4f8b\u3092\u53c2\u8003\u306b\u3055\u305b\u3066\u8cb0\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u2192\u3000<a href=\"http:\/\/code.google.com\/p\/oauth\/\" target=\"_blank\">oauth &#8211; Project Hosting on Google Code<\/a> <small>[code.google.com]<\/small><\/p>\n<p class=\"spacer\">&nbsp;<\/p>\n<pre class=\"super-pre-small\"><code>\/\/ \u30a2\u30d7\u30ea\u306e\u8a2d\u5b9a\r\n$id = '123456';\r\n$consumer_key = 'abcdef';\r\n$consumer_secret = 'uvwxyz';\r\n\r\n\/\/ API\u306eURL\r\n$end_point = 'http:\/\/example.jp\/foo\/bar\/@app';\r\n\r\n\/\/ \u30d1\u30e9\u30e1\u30fc\u30bf\r\n$get_params = array('xoauth_requestor_id' => $id, 'format' => 'json');\r\n$put_data = json_encode(array('data' => '\u307b\u3052\u307b\u3052'));\r\n\r\n$cons = new OAuthConsumer($consumer_key, $consumer_secret, NULL);\r\n$req = OAuthRequest::from_consumer_and_token($cons, NULL, 'PUT', $end_point, $get_params);\r\n$req->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $cons, NULL);\r\n\r\n$url = $end_point . '?' . http_build_query($get_params);\r\n$curl = curl_init($url);\r\ncurl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');\r\ncurl_setopt($curl, CURLOPT_RETURNTRANSFER, true);\r\ncurl_setopt($curl, CURLOPT_FAILONERROR, false);\r\ncurl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);\r\ncurl_setopt($curl, CURLOPT_POSTFIELDS, $put_data);\r\n$auth_header = $req->to_header();\r\ncurl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application\/json', $auth_header));\r\n\r\n$response = curl_exec($curl);\r\n$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);\r\ncurl_close($curl);\r\n<\/code><\/pre>\n<p class=\"spacer\">&nbsp;<\/p>\n<p>curl\u3067PUT\u3059\u308b\u65b9\u6cd5\u306f\u5e7e\u3064\u304b\u3042\u308b\u3088\u3046\u306a\u306e\u3067\u3059\u304c\u3001\u3053\u3061\u3089\u306e\u65b9\u6cd5\u304c\u4e00\u756a\u30b7\u30f3\u30d7\u30eb\u3060\u3063\u305f\u306e\u3067\u53c2\u8003\u306b\u3055\u305b\u3066\u8cb0\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u2192\u3000<a href=\"http:\/\/www.php.net\/manual\/ja\/function.curl-setopt.php#96056\" target=\"_blank\">PHP Manual\u3000curl_setopt (Ed Cradock\u6c0f 05-Feb-2010 06:47\u306e\u30b3\u30e1\u30f3\u30c8)<\/a> <small>[www.php.net]<\/small><\/p>\n<p class=\"spacer\">&nbsp;<\/p>\n<p>\u3068\u308a\u3042\u3048\u305a\u52d5\u4f5c\u3059\u308b\u3053\u3068\u306f\u78ba\u8a8d\u3057\u307e\u3057\u305f\u304c\u3001\u3042\u307e\u308a\u672c\u6c17\u3067\u4f7f\u3063\u3066\u3044\u306a\u3044\u305f\u3081\u3001\u4f55\u304b\u30c4\u30c3\u30b3\u30df\u304c\u3042\u308a\u307e\u3057\u305f\u3089\u304a\u9858\u3044\u3057\u307e\u3059\u3002<\/p>\n<p>DELETE\u30e1\u30bd\u30c3\u30c9\u3082\u3053\u306e\u5fdc\u7528\u3067\u3044\u3051\u308b\u306e\u3067\u3059\u304c\u3001\u305d\u308c\u306f\u307e\u305f\u5f8c\u65e5\u306b\u3067\u3082\u307e\u3068\u3081\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p class=\"spacer\">&nbsp;<\/p>\n<p><strong><em>\u95a2\u9023\uff1a<\/em><\/strong><\/p>\n<ul>\n<li><em><a href=\"http:\/\/ke-tai.org\/blog\/2010\/09\/28\/opensocialoauthframework\/\">\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3092\u4f7f\u3063\u3066Opensocial\u306eOAuth\u8a8d\u8a3c\u3092\u901a\u3059\u5834\u5408\u306e\u30cf\u30de\u308a\u3069\u3053\u308d<\/a><\/em> <img decoding=\"async\" style=\"border:0px\" src=\"http:\/\/b.hatena.ne.jp\/entry\/image\/small\/http:\/\/ke-tai.org\/blog\/2010\/09\/28\/opensocialoauthframework\/\" alt=\"\" \/><\/li>\n<li><em><a href=\"http:\/\/ke-tai.org\/blog\/2010\/09\/27\/rubykaigi2010keitaiopensocial\/\">\u65e5\u672cRuby\u4f1a\u8b702010\u306e\u767a\u8868\u3067\u4f7f\u308f\u308c\u305f\u30b9\u30e9\u30a4\u30c9\u8cc7\u6599\u300cRuby on Rails\u3067\u306f\u3058\u3081\u308b\u643a\u5e2f\u96fb\u8a71\u5411\u3051\u30aa\u30fc\u30d7\u30f3\u30bd\u30fc\u30b7\u30e3\u30eb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u300d<\/a><\/em> <img decoding=\"async\" style=\"border:0px\" src=\"http:\/\/b.hatena.ne.jp\/entry\/image\/small\/http:\/\/ke-tai.org\/blog\/2010\/09\/27\/rubykaigi2010keitaiopensocial\/\" alt=\"\" \/><\/li>\n<li><em><a href=\"http:\/\/ke-tai.org\/blog\/2010\/05\/14\/reviewmixiopensocial\/\">\u30d6\u30c3\u30af\u30ec\u30d3\u30e5\u30fc\uff1amixi\u30a2\u30d7\u30ea\u3092\u3064\u304f\u308d\u3046!OpenSocial\u3067\u5b66\u3076\u30bd\u30fc\u30b7\u30e3\u30eb\u30a2\u30d7\u30ea<\/a><\/em> <img decoding=\"async\" style=\"border:0px\" src=\"http:\/\/b.hatena.ne.jp\/entry\/image\/small\/http:\/\/ke-tai.org\/blog\/2010\/05\/14\/reviewmixiopensocial\/\" alt=\"\" \/><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6628\u65e5\u306b\u5f15\u304d\u7d9a\u304dOpensocial\u30cd\u30bf\u3067\u3059\u3002 \u30bd\u30fc\u30b7\u30e3\u30eb\u30b2\u30fc\u30e0\u306a\u3069\u3092\u4f5c\u6210\u3059\u308b\u969b\u306bOpensocial\u306eRESTfulAPI\u3092\u4f7f\u3046\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002 GET\u3084POST\u306e\u60c5\u5831\u306f\u3001\u691c\u7d22\u3059\u308b\u3068\u305d\u308c\u306a\u308a\u306b\u51fa\u3066\u304d\u307e\u3059\u3057\u3001\u30b5\u30a4\u30c8\u4e0a\u306b\u3082\u30b5 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[195,671,579,578],"_links":{"self":[{"href":"http:\/\/ke-tai.org\/blog\/wp-json\/wp\/v2\/posts\/4086"}],"collection":[{"href":"http:\/\/ke-tai.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ke-tai.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ke-tai.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/ke-tai.org\/blog\/wp-json\/wp\/v2\/comments?post=4086"}],"version-history":[{"count":13,"href":"http:\/\/ke-tai.org\/blog\/wp-json\/wp\/v2\/posts\/4086\/revisions"}],"predecessor-version":[{"id":4099,"href":"http:\/\/ke-tai.org\/blog\/wp-json\/wp\/v2\/posts\/4086\/revisions\/4099"}],"wp:attachment":[{"href":"http:\/\/ke-tai.org\/blog\/wp-json\/wp\/v2\/media?parent=4086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ke-tai.org\/blog\/wp-json\/wp\/v2\/categories?post=4086"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ke-tai.org\/blog\/wp-json\/wp\/v2\/tags?post=4086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}