ãPHPãDropbox API ã試ãã¦ã¿ã
ã©ããã
Heroku 㧠PHP + Nginx ãªç°å¢ãæ§ç¯ããã³ãã³åç»ã®RSSãã£ã¼ãã Dropbox ã«ä¿åãã¦ã¿ã¾ããã
ç°¡åã«èª¬æããã¨ï½¥ï½¥ï½¥URL å©ããã Dropbox ã« XML ãã¡ã¤ã«ãä¿åããã¾ããã£ã¦è©±ã§ãã
ã§ããã³ã¼ãèªãã ãã© Access Token ã®åå¾ã¯ã©ãããã®ï¼ãã£ã¦æããã人ãããããç¥ãã¾ããã・・・
御å
ãªãããgit ã³ãã³ããåãã¦ä½¿ãã¾ããã®ã§ git rm ~ ã¨ãã³ãã³ãå©ãããæ¶ãã¾ãããã¾ããç©ççã«æ¶ããã¨ã¯æã£ã¦ã¾ããã§ããï½
ããè¨ãããã§ä»åã®è¨äºã¯ Access Token åå¾å¾ã®è©±ã«ãªãã¾ãã
ãã£ã¬ã¯ããªæ§é
dropbox-sdk/ âââ index.php âââ lib â  âââ Dropbox âââ main   âââ upload.php
upload.php
<?php # Include the Dropbox SDK libraries require_once "../lib/Dropbox/autoload.php"; use \Dropbox as dbx; $json = '{"key": "xxxxx","secret": "xxxxx","access_type": "xxxxx"}'; $appInfo = null; $dbxConfig = null; $accessToken = null; $client = null; try { $jsonArr = json_decode($json, true); $appInfo = dbx\AppInfo::loadFromJson($jsonArr); $dbxConfig = new dbx\Config($appInfo, "PHP-Example/1.0"); $accessToken = new dbx\AccessToken("xxxxx", "xxxxx"); $client = new dbx\Client($dbxConfig, $accessToken); # nico_daily_ranking_yyyymmdd.xml $file_name = '/Rss/nico_daily_ranking_'.date("Ymd").'.xml'; # VOCALOID 24æé åçã©ã³ãã³ã° $data = file_get_contents('http://www.nicovideo.jp/ranking/view/daily/vocaloid?rss=2.0&lang=ja-jp'); $client->uploadFileFromString($file_name, dbx\WriteMode::add(), $data); } catch (Exception $e) { echo $e->getMessage(); } unset($appInfo); unset($dbxConfig); unset($accessToken); unset($client); ?>
Heroku ã«ãããã¤ãã
åè : Heroku上に最新のPHP5.4 + nginx環境を30秒で構築する - へびにっき
$ git init $ git add . $ git commit -m "first commit" $ heroku create -s cedar -b git://github.com/iphoting/heroku-buildpack-php-tyler.git [ã¢ããªå] $ git push heroku master
çµæ
äºå®éã URL å©ããã XML ãã¡ã¤ã«ãä¿åããã¾ããã
é£ç¶ã§å©ã㨠hoge(2).xml ã¿ããã«åæã«ãªãã¼ã ãã¦ä¿åããã¾ããã
ä½æ ãããªããã°ã©ã ä½ã£ãã®ï¼
ããããç§ã¯ãã³ãã³åç»ãå©ç¨ãã¦ã¾ããããããã¼ã«ãã¤ãã¯èå³ãããããã ããã ãã§ãã
ã©ã³ãã³ã°ãã°ã©ãã«ãã¦ã¿ãããé¢ç½ãããªï¼ã£ã¦ã®ãå§ã¾ãã§ãã
ã¾ããæ¢ã«è²ã
ãªãµã¼ãã¹ãããµã¤ããããä¸ã§ä»æ´ãªæããåããã¾ããã・・・ã
å ã¿ã«ãDropbox ã® API ãå©ãã©ã¤ãã©ãªã¯å¹¾ã¤ãçºè¦ã§ããã®ã§ãããä¸æãåä½ããªãã£ãããããã®ã¯ Heroku ã PostgreSQL ãªã®ã§ã³ã¢ãæ¸ãæãã¦å¯¾å¿ããã¦åä½ããã¦ã¿ããè¦äºã«ããã・・・ã
以ä¸ã§ãã