You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

kaftanati's avatar
kaftanati
Helpful | Level 6
8 years ago

How I can do unlink() for account at Android (with API v2)?

Android Core API v1 have method for unlink account from app:

mAccountManager.unlink();

Now I can't find same functional.

  • In the API v2 Java SDK, the equivalent would be the calling tokenRevoke to revoke the token, and then throwing the local copy of the access token.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    In the API v2 Java SDK, the equivalent would be the calling tokenRevoke to revoke the token, and then throwing the local copy of the access token.

    • kaftanati's avatar
      kaftanati
      Helpful | Level 6

      My mistake was - I didn't clear local stored token. Now all worked, thanks!

    • Oleg3's avatar
      Oleg3
      Helpful | Level 5

      Hello,

      I use this DropboxClientFactory:

       

      public class DropboxClientFactory {
      
          private static DbxClientV2 sDbxClient;
      
          public static void init(String accessToken) {
          	if (sDbxClient == null) {
                  DbxRequestConfig requestConfig = DbxRequestConfig.newBuilder("myApp").build();
                  sDbxClient = new DbxClientV2(requestConfig, accessToken);
          	}
          }
          
          public static DbxClientV2 getClient() {
              if (sDbxClient == null) {
                  throw new IllegalStateException("Client not initialized.");
              }
              return sDbxClient;
          }
      
          public static Boolean tokenRevoke() {
          	Boolean result = false;
          	if (sDbxClient != null) {
          		try {
          		   sDbxClient.auth().tokenRevoke();
          		   result = true;
          		} catch (DbxApiException e) {
          		} catch (DbxException e) {
      	       	}
          	} 
      		return result;
          }   
      }

       

      I have some questions/problems:

       

      1. In most examples, DbxRequestConfig is like this (with .withHttpRequestor(new OkHttp3Requestor(OkHttp3Requestor.defaultOkHttpClient())))

      DbxRequestConfig requestConfig = DbxRequestConfig.newBuilder("examples-v2-demo")
      .withHttpRequestor(new OkHttp3Requestor(OkHttp3Requestor.defaultOkHttpClient()))
      .build();

      I use it without "OkHttpRequestor". Is it necessary?

      I would like to add it, but i recive the error on it: "The type okhttp3.OkHttpClient cannot be resolved. It is indirectly referenced from required .class files". How could I resolve it?

       

      2. App links to dropbox and upload/download the file without the problem. But on revoke the token (calling tokenRevoke() ) i recieve the error: "android.os.NetworkOnMainThreadException".  And this error is not catched by DbxApiException and  DbxException.

      What is wrong? Why this error is not catched? What type of Exception i need to use to catch all errors of Dropbox?

      I use general "Exception e", it catches the error, but "e.getMessage()" returns NULL.

       

      Thanks in advance.