DropboxUnlinkedException - 如果您没有在会话中设置访问令牌对,或者如果用户已撤销访问

DropboxUnlinkedException - if you have not set an access token pair on the session, or if the user has revoked access

我正在尝试将文件上传到保管箱。我已经配置了清单文件,并编写了以下代码。请帮助我了解我在这里缺少的东西。 Activity onClick

Intent uploadToDropbox = new Intent(this, SUploadDB2Dropbox.class); 
            startService(uploadToDropbox) ;

服务 SUploadDB2Dropbox

private DropboxAPI<AndroidAuthSession> mDBApi;

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        AppKeyPair appKeys = new AppKeyPair(God.DROPBOX_APP_KEY,
                God.DROPBOX_APP_SECRET);
        AndroidAuthSession session = new AndroidAuthSession(appKeys);
        mDBApi = new DropboxAPI<AndroidAuthSession>(session);
        mDBApi.getSession().startOAuth2Authentication(this);
        UploadDB2DropBox upload2DropBox = new UploadDB2DropBox(this, mDBApi);
        upload2DropBox.execute();
        return super.onStartCommand(intent, flags, startId);
    }

UploadDB2DropBox AsyncTask

@Override
    public String doInBackground(Object... params) {
        File file = new File(context.getDatabasePath(God.TABLE_ACTIVATIONS)
                + ".db");
        Log.d(God.TAG,
                "Database path "
                        + context.getDatabasePath(God.TABLE_ACTIVATIONS));

        FileInputStream inputStream = null;
        try {
            String newFileName;
            inputStream = new FileInputStream(file);

            newFileName = "/" + God.TABLE_ACTIVATIONS
                    + Calendar.getInstance().getTimeInMillis() + ".db";
            Log.d(God.TAG, "File path " + file.getName() + " len "
                    + inputStream.available());
            Log.d(God.TAG, " New Filename " + newFileName);
            Entry response = mDBApi.putFile(newFileName, inputStream,
                    file.length(), null, null);
            Log.d(God.TAG, "Uploaded file is " + response.rev);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            Log.e(God.TAG, "FileNotFoundException");
        } catch (DropboxException e) {
            e.printStackTrace();n
            Log.e(God.TAG, "DropboxException");
        } catch (IOException e) {
            Log.e(God.TAG, "IOException");
            e.printStackTrace();
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    Log.e(God.TAG, "IOException");
                }
            }
        }
        return null;
    }

我收到保管箱异常。屏幕确实导航到保管箱 Allow user 屏幕(尽管每次都是)。

Logcat

02-23 11:44:19.435: D/AutoActivate(27289): Database path /data/data/com.swipex.autoactivate/databases/activations
02-23 11:44:19.436: D/AutoActivate(27289): File path activations.db len 8372224
02-23 11:44:19.546: D/AutoActivate(27289):  New Filename /activations1424672059436.db
02-23 11:44:19.702: E/AutoActivate(27289): DropboxException

清单文件

<activity
            android:name="com.dropbox.client2.android.AuthActivity"
            android:configChanges="orientation|keyboard"
            android:launchMode="singleTask" >
            <intent-filter>
                <data android:scheme="db-KEY_VALUE_HERE" />

                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

我收到 UnlinkException

DropboxUnlinkedException - if you have not set an access token pair on the session, or if the user has revoked access.

我错过了什么?

我必须说糟糕的保管箱文档

public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d(God.TAG, "Initializing Dropbox");
        AppKeyPair appKeys = new AppKeyPair(God.DROPBOX_APP_KEY,
                God.DROPBOX_APP_SECRET);
        AndroidAuthSession session = new AndroidAuthSession(appKeys);
        mDBApi = new DropboxAPI<AndroidAuthSession>(session);
        mDBApi.getSession().startOAuth2Authentication(this);
        if (mDBApi != null && mDBApi.getSession().authenticationSuccessful()) {
            try {
                // Required to complete auth, sets the access token on the session
                mDBApi.getSession().finishAuthentication();
                UploadDB2DropBox upload2DropBox = new UploadDB2DropBox(this,
                        mDBApi);
                upload2DropBox.execute();

                //String accessToken = mDBApi.getSession().getOAuth2AccessToken();
            } catch (IllegalStateException e) {
                Log.i(God.TAG, "Error authenticating", e);
            }
        }
        return super.onStartCommand(intent, flags, startId);
    }

这很有帮助。我想知道为什么 dropbox 一直在请求 UI 的许可。如果我必须不断请求许可,那么使用这个 api 是愚蠢的。