2016-10-04 13 views
1

Dropboxアカウントが接続されているユーザーがダッシュボードにログインするときを確認しようとしています。私はこれをうまくやることができますが、アプリケーションフォルダがDropboxに存在するかどうかを確認する必要があります。そうしないと、ユーザーはファイルのアップロードを開始できず、ルートが存在しないためパスが存在しないため失敗します。私はむしろアップロードプロセスの間にこれを最初にキャッチしたいと思います。Dropbox App Folderが存在するかどうかを確認

私はfindErrorNonRootを使用しようとしていましたが、明らかにルートを受け入れていません。

$pathError = dbx\Path::findErrorNonRoot($dropboxPath); 

ユーザーが自分の "アプリケーション" フォルダを削除している場合、私はまた、場合isValid

$pathError = dbx\Path::isValid("/"); 

答えて

0

を試してみました、のDropbox APIは、Dropbox\Exception_InvalidAccessToken例外がスローされます。したがって、この例外を適切に処理する必要があります。例:

注:私はPHP7 Null coalescing operatorを使用しました。ルートアプリケーションフォルダがユーザを作成する(フォルダが最初に除去される)

サンプル出力

Connecting to Dropbox... 
Error: HTTP status 401 

Description: User has removed their App folder. 
1. Go to: https://www.dropbox.com/1/oauth2/authorize?locale=&client_id=2deadbeef2ofaft&response_type=code 
2. Click "Allow" (you might have to log in first). 
3. Copy the authorization code. 
Enter the authorization code here: IugIByIMdKkAAAAAAAAAhVTH02dF7LW70_fFEHHohXo 
Access Token: IugIByIMdKkAAAAAAAAAhtPGKSoVOBs557XXrq-zX57L4QRAmqiUTagktS7YDmg1 
Connecting to Dropbox... 
Array 
(
    [revision] => 1 
    [bytes] => 10 
    [thumb_exists] => 
    [rev] => 14ef8952b 
    [modified] => Tue, 04 Oct 2016 09:02:31 +0000 
    [mime_type] => text/plain 
    [path] => /working-draft.txt 
    [is_dir] => 
    [size] => 10 bytes 
    [root] => app_folder 
    [id] => id:rmvcpq3LHlAAAAAAAAAAAw 
    [client_mtime] => Tue, 04 Oct 2016 09:02:31 +0000 
    [icon] => page_white_text 
) 

サンプル出力(フォルダが最初に存在する)

Connecting to Dropbox... 
Array 
(
    [revision] => 2 
    [bytes] => 10 
    [thumb_exists] => 
    [rev] => 24ef8b68e 
    [modified] => Tue, 04 Oct 2016 09:18:20 +0000 
    [mime_type] => text/plain 
    [path] => /test.txt 
    [is_dir] => 
    [size] => 10 bytes 
    [root] => app_folder 
    [id] => id:VMaySA3Ug5AAAAAAAAAABA 
    [client_mtime] => Tue, 04 Oct 2016 09:18:20 +0000 
    [icon] => page_white_text 
) 

リンクをたどり、「許可」ボタンをクリックします。