1

以前に Dropbox API を使用したことがなく、Core と Sync の 2 つの API が利用可能であることに気付きましたが、どちらを使用すればよいかわかりません。ここに私がやろうとしていることについて少しあります:

ユーザーの Dropbox 上のフォルダをデバイスにミラーリングする、またはその逆の単純な双方向同期。フォルダには、任意のタイプのファイルを含めることができます。App Console でアプリを作成するときに、パーミッションを要求しましたが、完全なドロップボックスのパーミッションはコア API とのみ互換性があるようです。

どの API を使用する必要があるかを明確にできる人はいますか? ありがとう!

編集: ドロップボックスの完全なアクセス許可を持つアプリを作成しましたが、これは同期 API で動作しませんでした (作成ページに記載されているように)。代わりに、テキスト ファイルを許可する別のアプリを作成し、.dat ファイルを作成しました。その結果、次の結果が得られました。エラー:

DROPBOX_DISALLOWED: sync.hpp:300: app is not allowed to create file p(/c7/r6/t4.dat)

この特定の問題を回避する方法はありますか、それともコア API を使用する必要がありますか? アプリが特定のファイルの種類でしか動作しないという制限があるようです。

EDIT2:今テストするために使用している私のコード:

public void SyncTest() {
    try {
        DbxFileSystem dbxFs = DbxFileSystem.forAccount(mDbxAcctMgr.getLinkedAccount());

        DbxFile testFile = dbxFs.create(new DbxPath(getString(R.string.remote_path) + "hello.dat"));
        try {
            testFile.writeString("Hello Dropbox!");
        } catch(IOException ioe) {

        } finally {
            testFile.close();
            dbxFs.syncNowAndWait();
        }
    } catch(com.dropbox.sync.android.DbxException.Unauthorized ue) {
        alert(getString(R.string.unauth));
    } catch (com.dropbox.sync.android.DbxException se) {

    }
}

アプリの権限タイプは「テキスト ファイル」です。「Full Dropbox」でアプリを使用すると、別のエラーが発生します。

DROPBOX_ERROR_USAGE: sync.cpp:244: This app is not allowed to use the Sync API for file access.
4

3 に答える 3

1

私の一般的なアドバイスは、モバイル プラットフォームで Sync API を使用することです。その下にあるのは同じ Core API ですが、Sync API を使用すると、通常のファイル システムのように見える Dropbox を表示できます。これは通常、Core API を直接使用するよりも簡単に操作できます。

パーミッションに関しては、Sync API は「フル Dropbox」パーミッションをサポートしていないため、「ファイル タイプ」パーミッション (拡張子による特定のタイプのファイルへのアクセス) または「アプリ フォルダー」パーミッション (任意のタイプへのアクセス) のいずれかを使用する必要があります。ただし、Dropbox/Apps/ など、アプリ用に指定されたフォルダー内のみ)。

于 2013-10-02T17:21:22.423 に答える
1

I have never worked with the Core API but I am both able to download and receive files.

It is though worth mentioning, that the intention of the Sync API (likely also the core), is not to keep the local files up-to-date. Rather it is designed to let you retrieve the files available on Dropbox and download on the fly.

My use case needed the Dropbox files to be retrieve locally, so I run a sync algorithm that run through all the Dropbox files, checks modified and size and downloads all the, either new, or modified files to SD. The downloading is done using IntentServices. Issuing an IntentService for each file that needs to be downloaded.

So, for one way sync, Sync API works fine. The other way should be possible too, though I assume harder to manage.

Bottom line being that you should be able to do it but you have to do a lot of lifting yourself.

The few questions I have seen with the Core API, I have not spotted any huge differences, other than the Sync API lives in a specific Dropbox folder "Dropbox/apps/yourapp", Core API does not.

If that is the case I would recommend Sync API as it seems to be simpler to work with.

I am willing to post my code for the one way sync if you choose to go for it :)

Edit: Added my code for writing to Dropbox

public class DropboxWriter {

private static final String TAG = "DropboxWriter";

public static boolean writeAssetBinary(Context context, String assetFile,
        DbxFile toFile) {

    String tempsdpath = Environment.getExternalStorageDirectory()
            .toString() + "/temp";

    AssetManager assetManager = context.getAssets();

    OutputStream outputStream = null;
    InputStream inputStream = null;
    try {
        inputStream = assetManager.open(assetFile);
        outputStream = new FileOutputStream(tempsdpath + "/" + assetFile);
        byte buf[] = new byte[1024];
        int len;
        while ((len = inputStream.read(buf)) != -1) {
            outputStream.write(buf, 0, len);
        }

    } catch (IOException e) {
        Log.e(TAG, e.getMessage(), e);
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
            }
        }
        if (outputStream != null) {

            try {
                outputStream.flush();
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    try {
        File file = new File(tempsdpath, assetFile);
        toFile.writeFromExistingFile(file, false);
        return true;
    } catch (IOException e) {
        Log.e(TAG, e.getMessage(), e);
    } finally {
        toFile.close();
    }
    return false;
}

public static boolean writeAssetText(Context context, String assetFile,
        DbxFile toFile) {

    AssetManager assetManager = context.getAssets();
    ByteArrayOutputStream outputStream = null;
    InputStream inputStream = null;
    try {
        inputStream = assetManager.open(assetFile);
        outputStream = new ByteArrayOutputStream();
        byte buf[] = new byte[1024];
        int len;
        while ((len = inputStream.read(buf)) != -1) {
            outputStream.write(buf, 0, len);
        }
        outputStream.flush();
        outputStream.close();
        inputStream.close();
    } catch (IOException e) {
        Log.e(TAG, e.getMessage(), e);
    }

    try {
        toFile.writeString(outputStream.toString());
        return true;
    } catch (IOException e) {
        Log.e(TAG, e.getMessage(), e);
    } finally {
        toFile.close();
    }
    return false;
}
}

Up until this point I have only needed to write files from assets but could easily be rewritten to write from any other file.

于 2013-10-02T15:05:37.527 に答える