我试过创建一个文件。 我的应用程序挂起了
List<DbxFileInfo> infos = dbxFs.listFolder(DbxPath.ROOT);
这是我的日志消息:(我替换IP * * *。* * *。* * *。* * *)
10-23 09:11:39.330: I/com.dropbox.sync.android.CoreStandardHttpRequestor(4486): Created new socket: SSL socket over Socket[address=api.dropbox.com/***.***.***.***,port=443,localPort=45370]
10-23 09:11:41.200: E/libDropboxSync.so(err)(4486): client.cpp:79: bad_state: This app is not allowed to use the Sync API for file access.
10-23 09:11:42.200: I/libDropboxSync.so(cache)(4486): client.cpp:107: fetching access info
10-23 09:11:42.400: I/com.dropbox.sync.android.CoreStandardHttpRequestor(4486): Created new socket: SSL socket over Socket[address=api.dropbox.com/***.***.***.***,port=443,localPort=43962]
10-23 09:11:44.850: E/libDropboxSync.so(err)(4486): client.cpp:79: bad_state: This app is not allowed to use the Sync API for file access.
10-23 09:11:45.850: I/libDropboxSync.so(cache)(4486): client.cpp:107: fetching access info
10-23 09:11:46.060: I/com.dropbox.sync.android.CoreStandardHttpRequestor(4486): Created new socket: SSL socket over Socket[address=api.dropbox.com/***.***.***.***,port=443,localPort=50441]
10-23 09:11:47.600: W/libDropboxSync.so(thr)(4486): env.cpp:139: int dropbox_wait_for_first_sync(dbx_client*) should not be called on the main thread
10-23 09:11:50.530: E/libDropboxSync.so(err)(4486): client.cpp:79: bad_state: This app is not allowed to use the Sync API for file access.
10-23 09:11:51.530: I/libDropboxSync.so(cache)(4486): client.cpp:107: fetching access info
10-23 09:11:51.750: I/com.dropbox.sync.android.CoreStandardHttpRequestor(4486): Created new socket: SSL socket over Socket[address=api.dropbox.com/***.***.***.***,port=443,localPort=33341]
10-23 09:11:53.120: E/libDropboxSync.so(err)(4486): client.cpp:79: bad_state: This app is not allowed to use the Sync API for file access.
10-23 09:11:54.120: I/libDropboxSync.so(cache)(4486): client.cpp:107: fetching access info
10-23 09:11:54.330: I/com.dropbox.sync.android.CoreStandardHttpRequestor(4486): Created new socket: SSL socket over Socket[address=api.dropbox.com/***.***.***.***,port=443,localPort=39033]
我的java课程:
public class DropBoxCLAplication {
public static DbxAccountManager mDbxAcctMgr;
private static final String TAG = IBMCLAplication.class.getSimpleName();
private DbxFileSystem.PathListener m_observer;
static final int REQUEST_LINK_TO_DBX = 0;
DbxFileSystem dbxFs;
DbxFile dbFile;
private DbxFileSystem.SyncStatusListener m_syncstatus;
private DbxDatastoreManager mAccountManager;
public DropBoxCLAplication( DbxAccountManager mDbxAcctMgr){
try {
dbxFs = DbxFileSystem.forAccount(mDbxAcctMgr.getLinkedAccount());
mAccountManager = DbxDatastoreManager.localManager(mDbxAcctMgr);
mAccountManager.openDefaultDatastore();
m_observer = new DbxFileSystem.PathListener() {
public void onPathChange(DbxFileSystem dbxFileSystem, final DbxPath dbxPath, Mode mode) {
Log.v(TAG, "Sync change detected on dropbox, reloading " + dbxPath.getName());
try {
DbxFile fInfo = dbxFileSystem.open(dbxPath);
final boolean latest = fInfo.getSyncStatus().isLatest;
fInfo.close();
Log.v(TAG, "File " + dbxPath.getName() + " changed. Latest: " + latest);
dbxFileSystem.addSyncStatusListener(new DbxFileSystem.SyncStatusListener() {
public void onSyncStatusChange(DbxFileSystem dbxFileSystem) {
try {
DbxSyncStatus status = dbxFileSystem.getSyncStatus();
if (!status.anyInProgress()) {
// If we got triggered because of local changes we are already at latest version
// Otherwise we call the refresh callback
if (!latest) {
}
dbxFileSystem.removeSyncStatusListener(this);
}
} catch (DbxException e) {
e.printStackTrace();
}
}
});
} catch (DbxException e) {
e.printStackTrace();
}
}
};
m_syncstatus = new DbxFileSystem.SyncStatusListener() {
public void onSyncStatusChange(DbxFileSystem dbxFileSystem) {
DbxSyncStatus status = null;
try {
status = dbxFileSystem.getSyncStatus();
if (status.anyInProgress()) {
} else {
}
} catch (DbxException e) {
e.printStackTrace();
}
}
};
dbxFs.addSyncStatusListener(m_syncstatus);
dbxFs.addPathListener(m_observer, DbxPath.ROOT, DbxFileSystem.PathListener.Mode.PATH_ONLY);
doDropboxTest( dbxFs);
Log.i(TAG,dbxFs.getSyncStatus().isSyncActive+"");
} catch (Exception e) {
// TODO Auto-generated catch block
Log.e(TAG,"DropBoxCLAplication error "+e.toString());
}
}
private void doDropboxTest(DbxFileSystem dbxFs) {
try {
final String TEST_DATA = "Hello Dropbox";
final String TEST_FILE_NAME = "hello_dropbox.txt";
DbxPath testPath = new DbxPath(DbxPath.ROOT, TEST_FILE_NAME);
// Create DbxFileSystem for synchronized file access.
// Print the contents of the root folder. This will block until we can
// sync metadata the first time.
List<DbxFileInfo> infos = dbxFs.listFolder(DbxPath.ROOT);
Log.i(TAG,"\nContents of app folder:\n");
for (DbxFileInfo info : infos) {
Log.i(TAG," " + info.path + ", " + info.modifiedTime + '\n');
}
// Create a test file only if it doesn't already exist.
if (!dbxFs.exists(testPath)) {
DbxFile testFile = dbxFs.create(testPath);
try {
testFile.writeString(TEST_DATA);
} finally {
testFile.close();
}
Log.i(TAG,"\nCreated new file '" + testPath + "'.\n");
}
// Read and print the contents of test file. Since we're not making
// any attempt to wait for the latest version, this may print an
// older cached version. Use getSyncStatus() and/or a listener to
// check for a new version.
if (dbxFs.isFile(testPath)) {
String resultData;
DbxFile testFile = dbxFs.open(testPath);
try {
resultData = testFile.readString();
} finally {
testFile.close();
}
Log.i(TAG,"\nRead file '" + testPath + "' and got data:\n " + resultData);
} else if (dbxFs.isFolder(testPath)) {
Log.i(TAG,"'" + testPath.toString() + "' is a folder.\n");
}
} catch (IOException e) {
Log.i(TAG,"Dropbox test failed: " + e);
}
}
答案 0 :(得分:-2)
错误是“此应用不允许使用Sync API进行文件访问”。最常见的原因是尝试使用具有“Full Dropbox”权限的应用密钥,该密钥与Sync API不兼容。您需要创建一个具有“文件类型”或“应用程序文件夹”权限的应用程序。