cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

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

kaftanati
Helpful | Level 6
Go to solution

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

mAccountManager.unlink();

Now I can't find same functional.

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

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.

View solution in original post

9 Replies 9

Mark
Super User II
Go to solution
*moves to API forum*

 


:penguin::penguin: - :penguin: - :penguin: - :penguin:


Heart Did this post help you? If so please mark it for some Kudos below. 


:white_check_mark: Did this post fix your issue/answer your question? If so please press the 'Accept as Solution' button to help others find it.


:arrows_counterclockwise: Did this post not resolve your issue? If so please give us some more information so we can try and help - please remember we cannot see over your shoulder so be as descriptive as possible! 


 

Greg-DB
Dropbox Staff
Go to solution

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
Helpful | Level 6
Go to solution

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

Oleg3
Helpful | Level 5
Go to solution

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.

Greg-DB
Dropbox Staff
Go to solution

@Oleg3

1. Use of `OkHttpRequestor` (or `OkHttp3Requestor`) is not required. If you don't use it, the SDK will fall back to using `StandardHttpRequestor` by default.

 

If you do want to use one, you need to include the relevant OkHttp library, for example as shown here.

 

2. `NetworkOnMainThreadException` is not a Dropbox exception, so you can't catch it using a Dropbox exception type. You can catch it using `Exception`, but you should write your app to avoid it in the first place. In short, you can't make a network call (such as a Dropbox API call) on the mean thread. The Android `NetworkOnMainThreadException` documentation has more information, and there are some samples on StackOverflow as well.

Oleg3
Helpful | Level 5
Go to solution

Greg, thanks a lot.

 

I add new code to DropboxClientFactory for tokenRevoke() using AsyncTask:

 

    public static void revokeClient(final CallBack callBack) {new AsyncTask<Void, Void, Void>() {
    	protected Void doInBackground(Void... params) {
    		try {
    			sDbxClient.auth().tokenRevoke();
    		} catch (DbxException e) {
    		}
            return null;
    	} // doInBackground

        protected void onPostExecute(Void aVoid) {
        	sDbxClient = null;
            if (callBack != null)
            	callBack.onRevoke();
            }
        }.execute();
    } // revokeClient

    public interface CallBack{
        void onRevoke();
    } // CallBack 

But I dont know how to call it from the main thread. Could you help me?

 

Sorry for the arrogance..... and thanks in advance.

 

Greg-DB
Dropbox Staff
Go to solution
It sounds that's more about Java threading/tasks which is outside the scope of Dropbox API support, so I'm afraid I can't be of help with that.

Oleg3
Helpful | Level 5
Go to solution
Thanks at all.
p.s. I thought Dropbox has some example to do revoke the token (as it was done for v1).
Could you at least provide me to some referenece or example how to apply the revoke function?
Thanks.

Greg-DB
Dropbox Staff
Go to solution

Using tokenRevoke as discussed is the right way to revoke an access token using the Dropbox API v2 Java SDK. I don't believe we have a code sample for using that on Android in particular, but we do have a sample Android app that uses the SDK to make other calls. For example, it defines and calls a ListFolderTask. 

 

 

Need more support?