{"id":5673,"date":"2024-06-06T12:18:31","date_gmt":"2024-06-06T03:18:31","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=5673"},"modified":"2024-04-01T14:41:56","modified_gmt":"2024-04-01T05:41:56","slug":"post-5673","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/5673","title":{"rendered":"PHP\u304b\u3089DBX Platform\u3092\u5229\u7528\u3057\u3066Dropbox\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u524a\u9664\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u4ee5\u524d\u306b<a href=\"https:\/\/taitan916.info\/blog\/archives\/5660\" target=\"_blank\" rel=\"noopener\">PHP\u304b\u3089Dropbox\u306e\u30d5\u30a1\u30a4\u30eb\u4e00\u89a7\u306e\u30c7\u30fc\u30bf(\u30d5\u30a1\u30a4\u30eb\u540d\u3084\u66f4\u65b0\u65e5\u6642\u7b49)\u3092\u53d6\u5f97<\/a>\u3059\u308b\u3068\u3044\u3046\u8a18\u4e8b\u3092\u66f8\u3044\u305f\u304c\u3001\u305d\u306e\u30c7\u30fc\u30bf\u3092\u5229\u7528\u3057\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u6307\u5b9a\u3057\u305f\u4e0a\u3067\u5f53\u8a72\u30d5\u30a1\u30a4\u30eb\u3092Dropbox\u5185\u304b\u3089\u524a\u9664\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><span id=\"i\">\u5b9f\u88c5\u65b9\u6cd5<\/span><\/h2>\n<h3><span id=\"i-2\">\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/span><\/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\u524a\u9664\r\nfunction deleteFile( $access_token, $file ){\r\n    $url = 'https:\/\/api.dropboxapi.com\/2\/files\/delete_v2';\r\n\r\n    $headers = array(\r\n        'Authorization: Bearer ' . $access_token,\r\n        'Content-Type: application\/json',\r\n    );\r\n\r\n    $param = array(\r\n        \"path\" =&gt; $file,\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\r\n    curl_close($ch);\r\n\r\n    return $res;\r\n}\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\/\/\u524a\u9664\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u3092\u6307\u5b9a\r\n$file = '\/002.jpg';\r\n$flg = deleteFile($access_token, $file);\r\n<\/pre>\n<p>$file\u90e8\u5206\u306f\u30a2\u30d7\u30ea\u306e\u30eb\u30fc\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u304b\u3089\u898b\u305f\u30d1\u30b9\u3067\u6307\u5b9a\u3059\u308b\u3002\u307e\u305f\u3001$file\u306e\u7a7a\u30c1\u30a7\u30c3\u30af\u3084API\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u30b3\u30fc\u30c9\u304c200\u304b\u306e\u30c1\u30a7\u30c3\u30af\u3082\u5b9f\u904b\u7528\u3067\u306f\u5fc5\u8981\u304b\u3068\u601d\u308f\u308c\u308b\u3002<\/p>\n<h3>\u524a\u9664\u6642\u306e\u623b\u308a\u5024<\/h3>\n<p>\u524a\u9664\u6642\u306e\u623b\u308a\u5024\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u9055\u3044\u304c\u3042\u3063\u305f\u3002error_summary\u3082\u3057\u304f\u306ferror\u304c\u8fd4\u3063\u3066\u304d\u3066\u3044\u308b\u5834\u5408\u306f\u30a8\u30e9\u30fc\u51e6\u7406\u3092\u884c\u3046\u3001\u3068\u3044\u3046\u5f62\u306b\u306a\u308a\u305d\u3046\u3002<\/p>\n<h4>\u524a\u9664\u6210\u529f<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">{\r\n    \"metadata\": {\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:xxxxxxxxxxxxxxxxxxx\",\r\n        \"client_modified\": \"2024-03-29T07:43:13Z\",\r\n        \"server_modified\": \"2024-03-29T07:43:13Z\",\r\n        \"rev\": \"xxxxxxxxxxxxxxxxxxx\",\r\n        \"size\": 128914,\r\n        \"is_downloadable\": true,\r\n        \"content_hash\": \"xxxxxxxxxxxxxxxxxxx\"\r\n    }\r\n}<\/pre>\n<h4>\u524a\u9664\u5931\u6557(\u30d5\u30a1\u30a4\u30eb\u304c\u898b\u3064\u304b\u3089\u306a\u3044\u5834\u5408)<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">{\r\n    \"error_summary\": \"path_lookup\/not_found\/.\",\r\n    \"error\": {\r\n        \".tag\": \"path_lookup\",\r\n        \"path_lookup\": {\r\n            \".tag\": \"not_found\"\r\n        }\r\n    }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u6240\u611f<\/h2>\n<h3>\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u30b7\u30b9\u30c6\u30e0\u304c\u4f5c\u308c\u305d\u3046<\/h3>\n<p>Dropbox\u3078\u306e\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3001\u4e00\u89a7\u53d6\u5f97\u3001\u30d5\u30a1\u30a4\u30eb\u524a\u9664\u304c\u53ef\u80fd\u306b\u306a\u3063\u305f\u306e\u3067\u3001\u4f55\u3089\u304b\u306e\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u7528\u30d5\u30a1\u30a4\u30eb\u3092\u5b9a\u671f\u7684\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u3001\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u6570\u304c\u3007\u4ee5\u4e0a\u306b\u306a\u3063\u305f\u3089\u4e00\u756a\u53e4\u3044\u3082\u306e\u3092\u524a\u9664\u3068\u30ed\u30b0\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u307f\u305f\u3044\u306a\u6a5f\u80fd\u3082\u642d\u8f09\u3057\u305f\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u30b7\u30b9\u30c6\u30e0\u304c\u4f5c\u308c\u305d\u3046\u3002<\/p>\n<h3>\u30e9\u30a4\u30d6\u30e9\u30ea\u3082\u5229\u7528\u3057\u3066\u307f\u305f\u3044<\/h3>\n<p>Dropbox\u3068PHP\u9023\u643a\u306e\u65e5\u672c\u8a9e\u60c5\u5831\u304c\u5c11\u306a\u3044\u4e0a\u3001API\u306e\u64cd\u4f5c\u65b9\u6cd5\u3082\u305d\u308c\u306a\u308a\u306b\u96e3\u6613\u5ea6\u304c\u9ad8\u304f\u8272\u3005\u3068\u96e3\u5100\u3057\u305f\u3002<\/p>\n<p><a href=\"https:\/\/www.dropbox.com\/developers\/documentation\/communitysdks\" target=\"_blank\" rel=\"noopener\">\u516c\u5f0f\u30b5\u30a4\u30c8<\/a>\u306b\u4ee5\u4e0b\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u7d39\u4ecb\u304c\u3042\u3063\u305f\u306e\u3067\u8a66\u3057\u3066\u307f\u305f\u3044\u3068\u3053\u308d\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/kunalvarma05\/dropbox-php-sdk\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/kunalvarma05\/dropbox-php-sdk<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/spatie\/dropbox-api\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/spatie\/dropbox-api<\/a><\/p>\n<p>\u516c\u5f0f\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u306f\u306a\u3044\u3088\u3046\u3060\u3051\u3069\u3001\u30d0\u30cb\u30e9PHP\u3088\u308a\u3082\u3063\u3068\u7c21\u5358\u306bAPI\u304c\u64cd\u4f5c\u3067\u304d\u308c\u3070\u3044\u3044\u306a\u3068\u601d\u3046\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u53c2\u8003\u30b5\u30a4\u30c8<\/h2>\n<p><a href=\"https:\/\/pikopiko.blog\/1059\/\" target=\"_blank\" rel=\"noopener\">https:\/\/pikopiko.blog\/1059\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u524d\u306bPHP\u304b\u3089Dropbox\u306e\u30d5\u30a1\u30a4\u30eb\u4e00\u89a7\u306e\u30c7\u30fc\u30bf(\u30d5\u30a1\u30a4\u30eb\u540d\u3084\u66f4\u65b0\u65e5\u6642\u7b49)\u3092 ... <\/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-5673","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\/5673","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=5673"}],"version-history":[{"count":3,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/5673\/revisions"}],"predecessor-version":[{"id":5676,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/5673\/revisions\/5676"}],"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=5673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=5673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=5673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}