@@ -37,7 +37,17 @@ class Dropbox implements Simulator
3737 *
3838 * @var string
3939 */
40- protected $ token ;
40+ private $ appKey ;
41+
42+ /**
43+ * @var string
44+ */
45+ private $ appSecret ;
46+
47+ /**
48+ * @var string
49+ */
50+ protected $ refreshToken ;
4151
4252 /**
4353 * Remote path
@@ -60,16 +70,6 @@ class Dropbox implements Simulator
6070 */
6171 protected $ time ;
6272
63- /**
64- * @var string
65- */
66- private $ appKey ;
67-
68- /**
69- * @var string
70- */
71- private $ appSecret ;
72-
7373 /**
7474 * (non-PHPDoc)
7575 *
@@ -85,12 +85,12 @@ public function setup(array $config)
8585 }
8686
8787 // check for mandatory options
88- $ this ->validateConfig ($ config , ['token ' , 'path ' , 'appKey ' , 'appSecret ' ]);
88+ $ this ->validateConfig ($ config , ['refreshToken ' , 'path ' , 'appKey ' , 'appSecret ' ]);
8989
90- $ this ->time = time ();
91- $ this ->token = $ config ['token ' ];
92- $ this ->appKey = $ config ['appKey ' ];
93- $ this ->appSecret = $ config ['appSecret ' ];
90+ $ this ->time = time ();
91+ $ this ->refreshToken = $ config ['refreshToken ' ];
92+ $ this ->appKey = $ config ['appKey ' ];
93+ $ this ->appSecret = $ config ['appSecret ' ];
9494 // make sure the path contains a leading slash
9595 $ this ->path = new Path (Util \Path::withLeadingSlash ($ config ['path ' ]), $ this ->time );
9696
@@ -179,7 +179,14 @@ protected function createCollector(Target $target) : Collector
179179 protected function createClient () : DropboxApi \Dropbox
180180 {
181181 if (!$ this ->client ) {
182- $ app = new DropboxApi \DropboxApp ($ this ->appKey , $ this ->appSecret , $ this ->token );
182+ $ app = new DropboxApi \DropboxApp ($ this ->appKey , $ this ->appSecret );
183+ $ client = new DropboxApi \Dropbox ($ app );
184+ $ authHelper = $ client ->getAuthHelper ();
185+ $ token = $ authHelper ->getRefreshedAccessToken (
186+ new DropboxApi \Models \AccessToken (['refresh_token ' => $ this ->refreshToken ])
187+ );
188+
189+ $ app = new DropboxApi \DropboxApp ($ this ->appKey , $ this ->appSecret , $ token ->getToken ());
183190 $ this ->client = new DropboxApi \Dropbox ($ app );
184191 }
185192 return $ this ->client ;
0 commit comments