We're making changes to the Community, so you may have received some notifications - thanks for your patience and welcome back. Learn more here.
Forum Discussion
Dolphin_2018
7 years agoExplorer | Level 4
Where should I locate the 'startOAuth2Authentication'?
Hi,
Question 1:
I'm totally new to Android Studio and I have to add a DropBox (SDK V2) files loading method to an existing project. As I understood I have to add the following line to my ...
- 7 years ago
[Cross-linking for reference: https://stackoverflow.com/questions/49070230/where-should-i-locate-startoauth2authentication ]
1) The startOAuth2Authentication method is what kicks off the Dropbox app authorization flow, so you should put it wherever in your app you handle the request from the user to connect their Dropbox account, e.g., the handler for tapping on a "Link to Dropbox" button in your app. (For example, that's what the Android example app does.)
The import lines are what import the necessary classes from the Dropbox SDK. (You don't need the "OpenWithActivity" one for your app though.) The import/"can't resolve" issues you're seeing seem to indicate that you don't have the SDK successfully installed. We recommend using either Gradle or Maven to install it, as documented in the readme. Make sure you have one of those set up and working correctly. If you have tried that, and it's not working, please share whatever Maven/Gradle error you're getting.
2) That getSharedPreferences call is to the Android getSharedPreferences method. The first parameter there is the "name" for the "Desired preferences file". You can supply whatever name you want.
That getString call is to the Android getString method. The first parameter is the "key" for "The name of the preference to retrieve". Likewise, the exact string is up to you.
With both of these, it's mostly just important that you're consistent with the strings you use, as it's how you will store and retrieve the account information. There's an example of these being used to store and retrieve the Dropbox access token in the Android example.
The getOAuth2Token method retrieves the access token, but only when the user is actually going through the app authorization flow. If they are not, it will return null. You should store and re-use the access token when you get it. That's done in the example here.
- 7 years agoThat line should run when you click on the "Login with Dropbox" button, not the "+" button. If you're seeing the "+", it means you've already connected Dropbox.
Anyway, I just tried it and it's working for me. (Also, make sure that you're actually debugging, and not just running. I.e., use the "bug" icon when in Android Studio, not the "play" icon.) - 7 years agoMake sure you have AuthActivity registered in your app's package, and only in one, as shown here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/AndroidManifest.xml#L26
If you had others registered but removed them, try restarting your device.
Greg-DB
7 years agoDropbox Staff
[Cross-linking for reference: https://stackoverflow.com/questions/49070230/where-should-i-locate-startoauth2authentication ]
1) The startOAuth2Authentication method is what kicks off the Dropbox app authorization flow, so you should put it wherever in your app you handle the request from the user to connect their Dropbox account, e.g., the handler for tapping on a "Link to Dropbox" button in your app. (For example, that's what the Android example app does.)
The import lines are what import the necessary classes from the Dropbox SDK. (You don't need the "OpenWithActivity" one for your app though.) The import/"can't resolve" issues you're seeing seem to indicate that you don't have the SDK successfully installed. We recommend using either Gradle or Maven to install it, as documented in the readme. Make sure you have one of those set up and working correctly. If you have tried that, and it's not working, please share whatever Maven/Gradle error you're getting.
2) That getSharedPreferences call is to the Android getSharedPreferences method. The first parameter there is the "name" for the "Desired preferences file". You can supply whatever name you want.
That getString call is to the Android getString method. The first parameter is the "key" for "The name of the preference to retrieve". Likewise, the exact string is up to you.
With both of these, it's mostly just important that you're consistent with the strings you use, as it's how you will store and retrieve the account information. There's an example of these being used to store and retrieve the Dropbox access token in the Android example.
The getOAuth2Token method retrieves the access token, but only when the user is actually going through the app authorization flow. If they are not, it will return null. You should store and re-use the access token when you get it. That's done in the example here.
- Dolphin_20187 years agoExplorer | Level 4
Thanks very much, I'm trying to implement it right now. In the meantime, I'm just wondering, why when I'm putting a breakpoint on the line:
Auth.startOAuth2Authentication(UserActivity.this, getString(R.string.app_key));
in the "Android" example, it's never stopping there? does it makes sense? it looks like the code is working properly and when I run it on my Nexus 5 device, click the "+" sign on the right bottom of the screen, and choose a file from my pictures collection, it succesfully transmited to my dropbox folder, but as I said it's never stop in the breakpoint.
How can it be? am I missing something in my understanding of this code?
Thanks.
- Greg-DB7 years agoDropbox StaffThat line should run when you click on the "Login with Dropbox" button, not the "+" button. If you're seeing the "+", it means you've already connected Dropbox.
Anyway, I just tried it and it's working for me. (Also, make sure that you're actually debugging, and not just running. I.e., use the "bug" icon when in Android Studio, not the "play" icon.)- Dolphin_20187 years agoExplorer | Level 4
Thanks very much now It's understood... I thought that it should Login to the Dropbox on every new run so I thought that it should stop on the breakpoint every time.
And yes I was in debugging mode (Shift + F9 on the Android Studio).
I will continue with this next week and let you know.
Thanks!
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,875 PostsLatest Activity: 37 minutes agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!