Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
donaldp
7 years agoCollaborator | Level 9
RespondPageWithJSRedirect() - where is this defined?
Hi, I am trying to set-up a Dropbox connection in .NET (Xamarin to be precise). I am following http://dropbox.github.io/dropbox-sdk-dotnet/html/T_Dropbox_Api_DropboxOAuth2Helper.htm. When I start ty...
- 7 years ago
Apologies for the confusion! The SDK doesn't offer an implementation of RespondPageWithJSRedirect. That's intended to be whatever page you wish to show to the user at that point in the process. (E.g., it can optionally contain a message for the user, and whatever branding/styling you want for your app.)
Here's where this is done in the example, and here's the HTML page, including the minimum JavaScript necessary, used for that example.
donaldp
7 years agoCollaborator | Level 9
Hi Greg,
As per Robert's advice, I put my own Apikey into SimpleTest, and ran it on Win10 in VS2017 (I also had to uncomment one of the Apikey references, so you may want to uncomment that in your repo. i.e. it got updated when I updated the main reference, but that line was still commented out). I get as far as the "Reset Settings?" prompt coming up, which is a start! Then, after answering, I got "Exception thrown: 'System.Net.HttpListenerException' in System.dll". Thinking this MAYBE the redirectUri not matching, I had a look through the code, and then added the corresponding setting "http://localhost:5000/admin/auth" to my redirectUri's. I also tried adding a trailing slash, as I'd seen along the way somewhere that this was required, but that didn't help either.
When I Google the error, it says...
"This exception is thrown by the HttpListener class and its associated classes when an error occurs during initialization of the HttpListener or while creating or sending a response to an HTTP request. For example, this exception is thrown if the HttpListener attempts to register a Uniform Resource Identifier (URI) prefix that is already registered.
Associated Tips
Make sure you are not attempting to register a URI prefix that is already registered.
If the URI prefix is already registered, this exception will occur"
I checked that port 5000 is not currently in use. Not sure what else to try with this? I've exhausted all the things that I can think of. Is there maybe something not set-up correctly somewhere?
Greg-DB
Dropbox Community Moderator
7 years agoThanks for the information. You shouldn't get that particular exception for a mismatch with the registered OAuth 2 redirect URIs for your app, so it must be something else, such as a potential port issue as you mentioned. If you attempt to use a redirect URI that isn't registered for your app, you'd see an error on the Dropbox web page itself. (That's only validated once the user hits the www.dropbox.com/oauth2/authorize... page with the client_id and redirect_uri parameters.)
Anyway, I'm also testing with Visual Studio 2017 on Windows 10, and I can't reproduce this HttpListenerException with the SimpleTest sample app. Can you print out the InnerException or Message in case it has more specific information on the issue?
One point of clarification though, the SimpleTest app uses the local port 52475 for the redirect URI, not 5000. Based on your mention of "http://localhost:5000/admin/auth", it sounds like you're actually looking at UniversalDemo, not SimpleTest.
If you are running the SimpleTest sample (as it sounds like you are, based on your reference to the "Reset Settings?" prompt), please check port 52475 is free (instead of 5000).
(And thanks for the note about uncommenting the ApiKey line. I'll ask the team to do that.)
- donaldp7 years agoCollaborator | Level 9
Thanks for further explanation on the process - not having done OAuth2 before I wasn't sure what to expect where or when. With more time spent on the host issue, this led to PROGRESS! :-) The suggestion on the website for a redirectUri is "https://localhost", and what I've found - in the end (cos at first I changed the code to match the website, not the other way around!) - was that the program ONLY works if you include the port and "authorize" (so "https://localhost" won't actually work, even if you had https://localhost in the code). I suggest you change the hint text on the website to include a port number and "authorize" (even if someone goes and changes them themselves. Situation not helped by freqent mentions of "you can put whatever you want there" - no you can't. If you don't include a port number it doesn't work. Ditto for the "authorize" if it's in your code. The only optional bits are http or https:, localhost or 127.0.0.1 - they all work either way. At least I've solved that now!).
So, went through the authorisation, and now the SimpleTest app is getting stuck a bit further on, at var context = await http.GetContextAsync();. Not crashing, just hung, therefore no error messages at all. Not sure what I need to do to get this line working? (I've let it sit there for several minutes now and still no sign of a response)
Note, the app was opening up a tab on my already-open browser. Just in case this was an issue, I closed my browser and reran the program (so it had a new browser all to itself), but it still hung. I can see the token there in the URL (yay! ;-) ), but it's not making it's way past that. :-(
Also, you're right. I was runing SimpleTest,but when I clicked on it to check the host I had accidentally clicked on the one underneath! Oops.
- Greg-DB7 years ago
Dropbox Community Moderator
I see, thanks for the feedback!
For the current issue, since you modified the code, please revert to the original SimpleTest code (or switch to a fresh copy). You should only have to add your app key; no other code changes are necessary for that sample.
It sounds like the app is hanging waiting on the user to come back to the previously configured redirect URI, but you may have accidentally changed what that path is, meaning it will never match.
- donaldp7 years agoCollaborator | Level 9
Woo hoo! Success! :-)
> you may have accidentally changed what that path is, meaning it will never match
It was actually getting stuck at the line before the one you have highlighted, but in any case loading in a fresh copy, and knowing what to put into the website now, got it all working. :-)
Now that we've got that little proof of concept done on my computer, I can get back to MY program and try and work out why IT'S not working (but now I can compare directly to SimpleTest, sicne I know that works). Will let you know how I go.
BTW, I still recommend you fix up that hint text (and be more specific with people when they ask what needs to go there). It DOES NOT work unless you include a port (and in the case of SimpleTest, you must also include the authorize). A proper example in the hint (i.e. showing that you need to the port number too) would be helpful.
Thanks! :-)
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If 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, Facebook or Instagram.
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!