{"id":5660,"date":"2024-06-03T11:35:40","date_gmt":"2024-06-03T02:35:40","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=5660"},"modified":"2024-04-01T14:41:37","modified_gmt":"2024-04-01T05:41:37","slug":"post-5660","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/5660","title":{"rendered":"PHP\u304b\u3089DBX Platform\u3092\u5229\u7528\u3057\u3066Dropbox\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u4e00\u89a7\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u4ee5\u524d\u306b<a href=\"https:\/\/taitan916.info\/blog\/archives\/4694\" target=\"_blank\" rel=\"noopener\">PHP\u304b\u3089Dropbox\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9<\/a>\u3059\u308b\u3068\u3044\u3046\u8a18\u4e8b\u3092\u66f8\u3044\u305f\u304c\u3001\u4eca\u56de\u306f\u305d\u306e\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u4e00\u89a7\u306e\u30c7\u30fc\u30bf(\u30d5\u30a1\u30a4\u30eb\u540d\u3084\u66f4\u65b0\u65e5\u6642\u7b49)\u3092\u53d6\u5f97\u3057\u305f\u3044\u3002\u4ee5\u4e0b\u306b\u5b9f\u88c5\u65b9\u6cd5\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2><span id=\"Dropbox\">Dropbox\u5074\u306e\u6e96\u5099<\/span><\/h2>\n<p>Dropbox\u5074\u306e\u6e96\u5099\u306b\u3064\u3044\u3066\u306f\u4ee5\u4e0b\u904e\u53bb\u8a18\u4e8b\u3092\u53c2\u8003\u306b\u300c\u30a2\u30d7\u30ea\u306e\u4f5c\u6210\uff5e\u30ea\u30d5\u30ec\u30c3\u30b7\u30e5\u30c8\u30fc\u30af\u30f3\u306e\u53d6\u5f97\u300d\u307e\u3067\u6e08\u307e\u305b\u3066\u304a\u304f\u3053\u3068\u3002<\/p>\n<p><a href=\"https:\/\/taitan916.info\/blog\/archives\/4694#Dropbox\" target=\"_blank\" rel=\"noopener\">https:\/\/taitan916.info\/blog\/archives\/4694#Dropbox<\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>\u5b9f\u88c5\u65b9\u6cd5<\/h2>\n<h3>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?php\r\nconst APP_KEY = '\u3010App key\u3011';\r\nconst APP_SECRET = '\u3010App secret\u3011';\r\nconst REFRESH_TOKEN = '\u3010\u30ea\u30d5\u30ec\u30c3\u30b7\u30e5\u30c8\u30fc\u30af\u30f3\u3011';\r\n\r\n\/\/\u4e00\u6642\u7684\u306a\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\u3092\u53d6\u5f97\r\nfunction getAccessToken() {\r\n    $url = 'https:\/\/api.dropboxapi.com\/oauth2\/token';\r\n    $data = [\r\n        'grant_type'    =&gt; 'refresh_token',\r\n        'refresh_token' =&gt; REFRESH_TOKEN,\r\n        'client_id'     =&gt; APP_KEY,\r\n        'client_secret' =&gt; APP_SECRET\r\n    ];\r\n\r\n    $ch = curl_init();\r\n    curl_setopt($ch, CURLOPT_URL, $url);\r\n    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\r\n    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));\r\n\r\n    $res = curl_exec($ch);\r\n    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);\r\n\r\n    $access_token = '';\r\n    if( !curl_errno($ch) &amp;&amp; $http_code == \"200\" ){\r\n        $res = json_decode($res, true);\r\n        $access_token = $res['access_token'];\r\n    } else {\r\n        echo \"ERROR: Failed to access Dropbox API : \" . curl_error($ch) . \"&lt;br&gt;\";\r\n    }\r\n\r\n    curl_close($ch);\r\n\r\n    return $access_token;\r\n}\r\n\r\n\/\/\u30d5\u30a1\u30a4\u30eb\u4e00\u89a7\u3092\u53d6\u5f97\r\nfunction getFileList( $access_token ){\r\n    $url = 'https:\/\/api.dropboxapi.com\/2\/files\/list_folder';\r\n\r\n    $headers = array(\r\n        'Authorization: Bearer ' . $access_token,\r\n        'Content-Type: application\/json',\r\n    );\r\n\r\n    \/\/\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u6307\u5b9a\u3057\u305f\u3044\u5834\u5408\u306f\u3053\u3061\u3089\u3067\u8a2d\u5b9a\u3059\u308b\r\n    $param = array(\r\n        \"path\" =&gt; \"\",\r\n    );\r\n\r\n    $options = array(\r\n        CURLOPT_URL =&gt; $url,\r\n        CURLOPT_HTTPHEADER =&gt; $headers,\r\n        CURLOPT_POST =&gt; true,\r\n        CURLOPT_POSTFIELDS =&gt; json_encode($param),\r\n        CURLOPT_RETURNTRANSFER =&gt; true,\r\n    );\r\n\r\n    $ch = curl_init();\r\n    curl_setopt_array($ch, $options);\r\n\r\n    $res = curl_exec($ch);\r\n    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);\r\n\r\n    curl_close($ch);\r\n\r\n    return $res;\r\n}\r\n\r\n\/\/\u4e00\u6642\u7684\u306a\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\u3092\u53d6\u5f97\r\n$access_token = getAccessToken();\r\n\r\n$file_list = getFileList($access_token);\r\nvar_dump($file_list);<\/pre>\n<p>\u300c\/\/\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u6307\u5b9a\u3057\u305f\u3044\u5834\u5408\u306f\u3053\u3061\u3089\u3067\u8a2d\u5b9a\u3059\u308b\u300d\u306e\u90e8\u5206\u306b\u3064\u3044\u3066\u3001\u30a2\u30d7\u30ea\u306e\u30eb\u30fc\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u5834\u5408\u306f\u7a7a(\"path\" =&gt; \"\")\u3067OK\u3002<\/p>\n<p>\u4eca\u56de\u306e\u5834\u5408\u3060\u3068\u300c\/\u30a2\u30d7\u30ea\/php_connection_test\u300d\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u304c\u5bfe\u8c61\u306b\u306a\u308b\u3002<\/p>\n<h3>\u51fa\u529b\u4f8b<\/h3>\n<p>\u4e0a\u8a18\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u304c\u6b63\u5e38\u306b\u5b9f\u884c\u3055\u308c\u308b\u3068var_dump\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u51fa\u529b\u3055\u308c\u308b\u7b48(\u4e00\u90e8\u4f0f\u5b57)\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">{\r\n    \"entries\": [\r\n        {\r\n            \".tag\": \"file\",\r\n            \"name\": \"002.jpg\",\r\n            \"path_lower\": \"\/002.jpg\",\r\n            \"path_display\": \"\/002.jpg\",\r\n            \"id\": \"id:xxxxxxxxxxxxxx\",\r\n            \"client_modified\": \"2024-03-29T07:43:13Z\",\r\n            \"server_modified\": \"2024-03-29T07:43:13Z\",\r\n            \"rev\": \"xxxxxxxxxxxxxx\",\r\n            \"size\": 128914,\r\n            \"is_downloadable\": true,\r\n            \"content_hash\": \"xxxxxxxxxxxxxx\"\r\n        },\r\n        {\r\n            \".tag\": \"file\",\r\n            \"name\": \"001.jpg\",\r\n            \"path_lower\": \"\/001.jpg\",\r\n            \"path_display\": \"\/001.jpg\",\r\n            \"id\": \"id:xxxxxxxxxxxxxx\",\r\n            \"client_modified\": \"2024-03-29T07:56:26Z\",\r\n            \"server_modified\": \"2024-03-29T07:56:26Z\",\r\n            \"rev\": \"xxxxxxxxxxxxxx\",\r\n            \"size\": 117227,\r\n            \"is_downloadable\": true,\r\n            \"content_hash\": \"xxxxxxxxxxxxxx\"\r\n        },\r\n        {\r\n            \".tag\": \"file\",\r\n            \"name\": \"003.jpg\",\r\n            \"path_lower\": \"\/003.jpg\",\r\n            \"path_display\": \"\/003.jpg\",\r\n            \"id\": \"id:xxxxxxxxxxxxxx\",\r\n            \"client_modified\": \"2024-03-29T07:56:37Z\",\r\n            \"server_modified\": \"2024-03-29T07:56:37Z\",\r\n            \"rev\": \"xxxxxxxxxxxxxx\",\r\n            \"size\": 120499,\r\n            \"is_downloadable\": true,\r\n            \"content_hash\": \"xxxxxxxxxxxxxx\"\r\n        }\r\n    ],\r\n    \"cursor\": \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\r\n    \"has_more\": false\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u305d\u306e\u4ed6<\/h2>\n<h3>\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306b\u3064\u3044\u3066<\/h3>\n<p>client_modified \/ server_modified\u306e\u65e5\u6642\u304c\u660e\u3089\u304b\u306b\u7570\u306a\u3063\u3066\u3044\u305f\u305f\u3081\u8abf\u3079\u3066\u307f\u308b\u3068\u3001<a href=\"https:\/\/www.dropboxforum.com\/t5\/Dropbox-API-Support-Feedback\/client-modified-on-filesListFolder-entries-all-in-UTC-lose-TZ\/td-p\/483158\" target=\"_blank\" rel=\"noopener\">\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306f\u5168\u3066UTC\u306b\u306a\u308b<\/a>\u3068\u306e\u3053\u3068\u3002<\/p>\n<h3>client_modified \/ server_modified\u306b\u3064\u3044\u3066<\/h3>\n<p><a href=\"https:\/\/www.dropboxforum.com\/t5\/Dropbox-API-Support-Feedback\/client-modified-on-filesListFolder-entries-all-in-UTC-lose-TZ\/td-p\/483158\" target=\"_blank\" rel=\"noopener\">\u30d5\u30a9\u30fc\u30e9\u30e0<\/a>\u306e\u4ee5\u4e0b\u5f15\u7528\u304c\u53c2\u8003\u306b\u306a\u308a\u305d\u3046\u3002<\/p>\n<blockquote><p>client_modified Timestamp(format=\"%Y-%m-%dT%H:%M:%SZ\") \u30d5\u30a1\u30a4\u30eb\u306e\u5834\u5408\u3001\u3053\u308c\u306f\u30d5\u30a1\u30a4\u30eb\u304c Dropbox \u306b\u8ffd\u52a0\u3055\u308c\u305f\u3068\u304d\u306b\u30c7\u30b9\u30af\u30c8\u30c3\u30d7 \u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306b\u3088\u3063\u3066\u8a2d\u5b9a\u3055\u308c\u305f\u5909\u66f4\u6642\u523b\u3067\u3059\u3002 \u3053\u306e\u6642\u9593\u306f\u691c\u8a3c\u3055\u308c\u3066\u3044\u306a\u3044\u305f\u3081 (Dropbox \u30b5\u30fc\u30d0\u30fc\u306f\u30c7\u30b9\u30af\u30c8\u30c3\u30d7 \u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c\u9001\u4fe1\u3057\u305f\u3082\u306e\u3092\u3059\u3079\u3066\u4fdd\u5b58\u3057\u307e\u3059)\u3001\u3053\u308c\u306f\u8868\u793a\u76ee\u7684 (\u4e26\u3079\u66ff\u3048\u306a\u3069) \u306b\u306e\u307f\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u3001\u30d5\u30a1\u30a4\u30eb\u304c\u5909\u66f4\u3055\u308c\u305f\u304b\u3069\u3046\u304b\u3092\u5224\u65ad\u3059\u308b\u305f\u3081\u306a\u3069\u306b\u306f\u4f7f\u7528\u3057\u306a\u3044\u3067\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>server_modified Timestamp(format=\"%Y-%m-%dT%H:%M:%SZ\") Dropbox \u4e0a\u3067\u30d5\u30a1\u30a4\u30eb\u304c\u6700\u5f8c\u306b\u5909\u66f4\u3055\u308c\u305f\u6642\u523b\u3002<\/p><\/blockquote>\n<p>\u57fa\u672c\u7684\u306b\u306fserver_modified\u3092\u4f7f\u3046\u5f62\u306b\u306a\u308b\u3068\u601d\u308f\u308c\u308b\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u53c2\u8003\u30b5\u30a4\u30c8<\/h2>\n<p><a href=\"https:\/\/pct.unifas.net\/programming\/php\/6550\/\" target=\"_blank\" rel=\"noopener\">https:\/\/pct.unifas.net\/programming\/php\/6550\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u524d\u306bPHP\u304b\u3089Dropbox\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u3068\u3044\u3046\u8a18\u4e8b\u3092\u66f8\u3044\u305f\u304c\u3001 ... <\/p>\n","protected":false},"author":1,"featured_media":3853,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[103],"class_list":["post-5660","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-dropbox"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/5660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=5660"}],"version-history":[{"count":5,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/5660\/revisions"}],"predecessor-version":[{"id":5672,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/5660\/revisions\/5672"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/3853"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=5660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=5660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=5660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}