dropbox-sdk-java
dropbox-sdk-java copied to clipboard
Auth.getOAuth2Token() returns null
I am using dropbox-sdk-java v2 for android. If I try to authenticate the flow from browser, I always get NULL. Issues related to this kind of question are #71 and #161 and they are already closed but none helpful.
My manifest looks like:
android:name="com.dropbox.core.android.AuthActivity"
android:configChanges="orientation|keyboard"
android:screenOrientation="portrait"
android:launchMode="singleTask"
<intent-filter>
<data android:scheme="db-XXXXXXXXXXXXX"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Have you implemented the app authorization flow as shown in the example Android app included with the SDK?:
https://github.com/dropbox/dropbox-sdk-java/tree/master/examples/android
You should refer to that as an example of how to implement the app authorization flow, which is accomplished via OAuth 2.
Your AndroidManifest.xml should be set up as shown here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/AndroidManifest.xml#L33
Specifically, you start the flow by calling startOAuth2Authentication as shown here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/UserActivity.java#L35
You complete the flow by calling getOAuth2Token in onResume as shown here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/DropboxActivity.java#L22
Your app can store and re-use the resulting access token for that user, as the example does here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/DropboxActivity.java#L24
If that's not working for you, please share the steps and specific code to reproduce the issue.
The problem is with Firefox Android Browser. later I tried the authorization process on Chrome Android browser and it worked perfectly. So if it worked for chrome then why not on firefox?
I just tried the authorization flow in the sample app using Firefox to authorize the app and it worked correctly for me.
If something isn't working as expected for you, please share:
- the steps to reproduce the issue, including relevant code
- any error/unexpected output you get
- the version number(s) of Android you're seeing this with
- the version number(s) of the Dropbox SDK you're seeing this with
- the version number(s) of Firefox you're seeing this with
I suspect your case is related to #242
@greg-db : I have a token and save shareprefences. After long time I open app again, I upload file with token in shareprefences, but I get error message "invalid_token". I want to ask you: in this sdk, do you have function refresh new token??? Please answer my question. Thank you
@songtoanht The public Dropbox API doesn't currently use refresh tokens, but Dropbox API access tokens can be revoked at any time by the user or app. If an access token does get revoked, you'd need to throw it away and prompt the user to re-authorize your app if they wish to continue using it.
This is issue thread is old and seems to be for a different issue than what you're referring to, so if something isn't working as expected, please open a new issue.
@greg-db Thank you so much. I want to confirm this issue. Because I saw many sdk to used refresh token to make behavior smoothly for the user. Thank you again
Have you implemented the app authorization flow as shown in the example Android app included with the SDK?:
https://github.com/dropbox/dropbox-sdk-java/tree/master/examples/android
You should refer to that as an example of how to implement the app authorization flow, which is accomplished via OAuth 2.
Your AndroidManifest.xml should be set up as shown here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/AndroidManifest.xml#L33
Specifically, you start the flow by calling
startOAuth2Authenticationas shown here:You complete the flow by calling
getOAuth2TokeninonResumeas shown here:https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/DropboxActivity.java#L22
Your app can store and re-use the resulting access token for that user, as the example does here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/DropboxActivity.java#L24
If that's not working for you, please share the steps and specific code to reproduce the issue.
Hi greg, i'm not quite familiar with kotlin, can you provide once more android java version ?
@abingvw It may be out of date now, but the previous Java Android example is still available at these links, corresponding to the steps in my quoted reply:
- https://github.com/dropbox/dropbox-sdk-java/tree/v5.3.0/examples/android
- https://github.com/dropbox/dropbox-sdk-java/blob/v5.3.0/examples/android/src/main/AndroidManifest.xml#L35
- https://github.com/dropbox/dropbox-sdk-java/blob/v5.3.0/examples/android/src/main/java/com/dropbox/core/examples/android/UserActivity.java#L36
- https://github.com/dropbox/dropbox-sdk-java/blob/v5.3.0/examples/android/src/main/java/com/dropbox/core/examples/android/DropboxActivity.java#L51
- https://github.com/dropbox/dropbox-sdk-java/blob/v5.3.0/examples/android/src/main/java/com/dropbox/core/examples/android/DropboxActivity.java#L53
fully noted, and thanks