com.dropbox.core.v2.users.FullAccount Java Examples

The following examples show how to use com.dropbox.core.v2.users.FullAccount. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActivityBackup.java    From fingen with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #2
Source File: DropboxSession.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@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);
    }
}
 
Example #3
Source File: DropboxRootListService.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@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);
    }
}
 
Example #4
Source File: DropboxHomeFinderFeature.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #5
Source File: UserActivity.java    From dropbox-sdk-java with MIT License 6 votes vote down vote up
@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();
}
 
Example #6
Source File: UserAccountTask.java    From fingen with Apache License 2.0 5 votes vote down vote up
@Override
protected FullAccount doInBackground(Void... params) {
    try {
        //get the users FullAccount
        return dbxClient.users().getCurrentAccount();
    } catch (DbxException e) {
        e.printStackTrace();
        error = e;
    }
    return null;
}
 
Example #7
Source File: UserAccountTask.java    From fingen with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #8
Source File: DropboxStorageProvider.java    From sling-whiteboard with Apache License 2.0 5 votes vote down vote up
@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.");
    }
}
 
Example #9
Source File: GetCurrentAccountTask.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
@Override
protected void onPostExecute(FullAccount account) {
    super.onPostExecute(account);
    if (mException != null) {
        mCallback.onError(mException);
    } else {
        mCallback.onComplete(account);
    }
}
 
Example #10
Source File: GetCurrentAccountTask.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
@Override
protected FullAccount doInBackground(Void... params) {

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

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

    return null;
}
 
Example #11
Source File: DbxClientV2IT.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
@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());
}
 
Example #12
Source File: Main.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
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());
}
 
Example #13
Source File: DropboxRootListService.java    From cyberduck with GNU General Public License v3.0 4 votes vote down vote up
public HomeNamespaceListProgressListener(final ListProgressListener listener, final FullAccount account) {
    this.listener = listener;
    this.account = account;
}
 
Example #14
Source File: UserAccountTask.java    From fingen with Apache License 2.0 votes vote down vote up
void onAccountReceived(FullAccount account); 
Example #15
Source File: GetCurrentAccountTask.java    From dropbox-sdk-java with MIT License votes vote down vote up
void onComplete(FullAccount result);