Java源码示例:com.dropbox.core.v2.users.FullAccount

示例1
protected void getUserAccount() {
    final SharedPreferences dropboxPrefs = getSharedPreferences("com.yoshione.fingen.dropbox", Context.MODE_PRIVATE);
    mEditTextDropboxAccount.setText(dropboxPrefs.getString(FgConst.PREF_DROPBOX_ACCOUNT, ""));
    String token = dropboxPrefs.getString("dropbox-token", null);
    if (token == null) return;
    new UserAccountTask(DropboxClient.getClient(token), new UserAccountTask.TaskDelegate() {
        @Override
        public void onAccountReceived(FullAccount account) {
            //Print account's info
            Log.d("User", account.getEmail());
            Log.d("User", account.getName().getDisplayName());
            Log.d("User", account.getAccountType().name());
            mEditTextDropboxAccount.setText(account.getEmail());
            dropboxPrefs.edit().putString(FgConst.PREF_DROPBOX_ACCOUNT, account.getEmail()).apply();
        }

        @Override
        public void onError(Exception error) {
            Log.d("User", "Error receiving account details.");
        }
    }).execute();
}
 
示例2
@Override
public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
    authorizationService.setTokens(authorizationService.authorize(host, prompt, cancel));
    try {
        final Credentials credentials = host.getCredentials();
        final FullAccount account = new DbxUserUsersRequests(client).getCurrentAccount();
        if(log.isDebugEnabled()) {
            log.debug(String.format("Authenticated as user %s", account));
        }
        credentials.setUsername(account.getEmail());
        switch(account.getAccountType()) {
            case BUSINESS:
                locking = new DropboxLockFeature(this);
        }
    }
    catch(DbxException e) {
        throw new DropboxExceptionMappingService().map(e);
    }
}
 
示例3
@Override
public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException {
    try {
        if(directory.isRoot()) {
            final FullAccount account = new DbxUserUsersRequests(session.getClient()).getCurrentAccount();
            switch(account.getAccountType()) {
                case BUSINESS:
                    return new DropboxListService(session).list(
                        directory.withAttributes(new PathAttributes().withVersionId(account.getRootInfo().getRootNamespaceId())),
                        new HomeNamespaceListProgressListener(listener, account));
            }
        }
        return new DropboxListService(session).list(directory, listener);
    }
    catch(DbxException e) {
        throw new DropboxExceptionMappingService().map("Listing directory {0} failed", e, directory);
    }
}
 
示例4
@Override
public Path find() throws BackgroundException {
    final Path directory = super.find();
    if(directory.isRoot()) {
        try {
            // Retrieve he namespace ID for a users home folder and team root folder
            final FullAccount account = new DbxUserUsersRequests(session.getClient()).getCurrentAccount();
            switch(account.getAccountType()) {
                case BUSINESS:
                    if(log.isDebugEnabled()) {
                        log.debug(String.format("Set root namespace %s", account.getRootInfo().getRootNamespaceId()));
                    }
                    return directory.withAttributes(new PathAttributes().withVersionId(account.getRootInfo().getRootNamespaceId()));
            }
        }
        catch(DbxException e) {
            throw new DropboxExceptionMappingService().map(e);
        }
    }
    return directory;
}
 
示例5
@Override
protected void loadData() {
    new GetCurrentAccountTask(DropboxClientFactory.getClient(), new GetCurrentAccountTask.Callback() {
        @Override
        public void onComplete(FullAccount result) {
            ((TextView) findViewById(R.id.email_text)).setText(result.getEmail());
            ((TextView) findViewById(R.id.name_text)).setText(result.getName().getDisplayName());
            ((TextView) findViewById(R.id.type_text)).setText(result.getAccountType().name());
        }

        @Override
        public void onError(Exception e) {
            Log.e(getClass().getName(), "Failed to get account details.", e);
        }
    }).execute();
}
 
示例6
@Override
protected FullAccount doInBackground(Void... params) {
    try {
        //get the users FullAccount
        return dbxClient.users().getCurrentAccount();
    } catch (DbxException e) {
        e.printStackTrace();
        error = e;
    }
    return null;
}
 
示例7
@Override
protected void onPostExecute(FullAccount account) {
    super.onPostExecute(account);

    if (account != null && error == null){
        //User Account received successfully
        delegate.onAccountReceived(account);
    }
    else {
        // Something went wrong
        delegate.onError(error);
    }
}
 
示例8
@Activate
private void activate(DropboxStorageProviderConfiguration configuration) {
    if (StringUtils.isNotEmpty(configuration.accessToken())) {
        DbxRequestConfig requestConfig = DbxRequestConfig.newBuilder(this.getClass().getName()).build();
        client = new DbxClientV2(requestConfig, configuration.accessToken());
        StandardHttpRequestor.Config longpollConfig = StandardHttpRequestor.Config.DEFAULT_INSTANCE.copy().withReadTimeout(5,
                TimeUnit.MINUTES).build();
        DbxRequestConfig pollingRequestConfig = DbxRequestConfig.newBuilder(this.getClass().getName() + "-longpoll")
                .withHttpRequestor(new StandardHttpRequestor(longpollConfig))
                .build();
        longPollClient = new DbxClientV2(pollingRequestConfig, configuration.accessToken());
        try {
            FullAccount account = client.users().getCurrentAccount();
            LOGGER.info("Initialised Dropbox provider for {}.", account.getName().getDisplayName());
            dropboxRootPath = configuration.remote_storage_provider_root();
            if (dropboxRootPath.isEmpty()) {
                dropboxRootPath = "/";
            }
            slingMountPoint = new Path(configuration.resource_provider_root());
            cursor = client.files()
                    .listFolderGetLatestCursorBuilder("/".equals(dropboxRootPath) ? "" : dropboxRootPath)
                    .withIncludeDeleted(true)
                    .withIncludeMediaInfo(false)
                    .withRecursive(true)
                    .start().getCursor();
        } catch (Exception e) {
            LOGGER.error("Unable to initialise a Dropbox Storage Provider for configuration {}.", configuration);
            throw new IllegalStateException(e);
        }
    } else {
        throw new IllegalStateException("The access token cannot be empty.");
    }
}
 
示例9
@Override
protected void onPostExecute(FullAccount account) {
    super.onPostExecute(account);
    if (mException != null) {
        mCallback.onError(mException);
    } else {
        mCallback.onComplete(account);
    }
}
 
示例10
@Override
protected FullAccount doInBackground(Void... params) {

    try {
        return mDbxClient.users().getCurrentAccount();

    } catch (DbxException e) {
        mException = e;
    }

    return null;
}
 
示例11
@Test
public void testAccountInfo() throws Exception {
    DbxClientV2 client = ITUtil.newClientV2();

    FullAccount full = client.users().getCurrentAccount();
    assertNotNull(full);
    assertNotNull(full.getName());
    assertNotNull(full.getAccountId());

    BasicAccount basic = client.users().getAccount(full.getAccountId());
    assertNotNull(basic);
    assertNotNull(basic.getName());
    assertEquals(basic.getAccountId(), full.getAccountId());
}
 
示例12
private static void testBasicSerialization(DbxClientV2 client) throws DbxException, IOException {
    // Make the /account/info API call.
    FullAccount expected = client.users().getCurrentAccount();
    assertNotNull(expected);

    String accountId = expected.getAccountId();
    assertNotNull(accountId);
    assertNotNull(expected.getName());

    BasicAccount actual = client.users().getAccount(accountId);
    assertNotNull(actual);
    assertEquals(actual.getAccountId(), expected.getAccountId());
    assertEquals(actual.getEmail(), expected.getEmail());
}
 
示例13
public HomeNamespaceListProgressListener(final ListProgressListener listener, final FullAccount account) {
    this.listener = listener;
    this.account = account;
}
 
示例14
void onAccountReceived(FullAccount account); 
示例15
void onComplete(FullAccount result);