cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Tell us what you want to see on the Community here!
Close

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: 

RespondPageWithJSRedirect() - where is this defined?

Highlighted

RespondPageWithJSRedirect() - where is this defined?

Collaborator | Level 8

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 typing in "RespondPageWithJSRedirect()" it isn't being detected anywhere by intellisense (Visual Studio 2017). I've got all the usings that have been specified on the quoted page, so I'm either mssing a nuget, or another using, or something like that. When I search for this string on the gitgub page https://github.com/dropbox/dropbox-sdk-dotnet/blob/master/dropbox-sdk-dotnet/Dropbox.Api/DropboxOaut... it only finds 2 instances - a comment and the call itself. Where is this defined? What do I need to add?

 

thanks,

  Donald.

1 Accepted Solution

Accepted Solutions
Highlighted

Re: RespondPageWithJSRedirect() - where is this defined?

Dropboxer

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.

View solution in original post

12 Replies 12
Highlighted

Re: RespondPageWithJSRedirect() - where is this defined?

Dropboxer

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.

View solution in original post

Highlighted

Re: RespondPageWithJSRedirect() - where is this defined?

Collaborator | Level 8

Hi Greg,

 

   Thanks for that. Sorry for slow response, but was away for Xmas, and now spent a while trying to get it working before replying. Making progress, but stuck now (and not getting as far as the RespondPageWithJSRedirect() code to see if that works unfortunately :-( ).

 

On Win10 I get as far as the System.Diagnostics.Process.Start(authorizeUri.ToString()); line, and get Exception thrown: 'System.ComponentModel.Win32Exception' in System.Diagnostics.Process.dll (Googling this not proving very helpful).

 

Tried on my Android phone when I got stuck on Windows, and only got to the previous line - http.Start(); - though I'm not sure what the problem is as Android throws out an awful lot of messages and I'm not sure what it is I'm looking for there?

BTW I'm still not sure I have the redirectUri set-up correctly (and could be the problem to begin with here) - responses here always amount to "you can put whatever you want there", which isn't helpful if you don't know what to put there to begin with! I'm using this (as per the code on your page)...

 

private const string LoopbackHost = "http://127.0.0.1:52475/";
private readonly Uri RedirectUri = new Uri(LoopbackHost + "authorize");
private readonly Uri JSRedirectUri = new Uri(LoopbackHost + "token");

 

So on Dropbox in the redirectUri, should that be "http://127.0.0.1/authorize", or "http://127.0.0.1:52475" or "http://127.0.0.1:52475/authorize", or...? I'm also not sure how to check on unused ports if it comes to that (I found a command, but the command doesn't say whether it's listing used or unused ports! And I don't know if the above message is because that port is busy or something else).

 

thanks,

  Donald.

Highlighted

Re: RespondPageWithJSRedirect() - where is this defined?

Dropboxer

Are you getting that error when trying to run the "SimpleTest" sample app? Have you made any modifications (other than plugging in an app key)? I just tried it in Visual Studio 2017 on Windows 10 and I didn't get that error unfortunately. Is there any other output in the log?

To clarify, are you also trying to run the "SimpleTest" on Android? That sample wasn't written for Android, nor does the .NET SDK itself officially support Android.

Based on that code snippet, the redirect URI would be "http://127.0.0.1:52475/authorize".

I can't offer insight on checking the ports on a system though, as that's not part of Dropbox.

Highlighted

Re: RespondPageWithJSRedirect() - where is this defined?

Collaborator | Level 8

Hi Greg,

> Are you getting that error when trying to run the "SimpleTest" sample app?

   I was coding my own test app from scratch, but following those 2 examples, so the answer is yes, kinda. Your remark has made me think I'll just try running the whole SimpleTest as is, and see if that works for me as is... but as I've found previously (like missing usings), there's a bunch of details that have been left out. See below for all the error messages I got.

> Is there any other output in the log?

Lots of messages, as usual, but only 2 errors. The 2nd was with the httplistener, and was further down, so may have been a flow-on from the first error. trying to fix the 1st error 1st, and see if that also fixes the 2nd error.

> To clarify, are you also trying to run the "SimpleTest" on Android? That sample wasn't written for Android, nor does the .NET SDK itself officially support Android.

As mentioned, I'm using Xamarin, which supports UWP, iOS and Android (plus some other platforms too). Coding is done in C#/.NET, and Xamarin takes care of the platform stuff in the background. They do have a Xamarin.Dropbox.Api - apparently they had to do a few hacks to make the Dropbox.Api work with Xamarin (maybe related to the fact that .NET doesn't officially support Android?) - and that is the one I'm using. It's available in nuget.

> Based on that code snippet, the redirect URI would be "http://127.0.0.1:52475/authorize".

Thanks.

Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'WebRequestHandler' could not be found (are you missing a using directive or an assembly reference?) SimpleTest D:\Users\Donald\Source\Repos\SimpleTest\SimpleTest\SimpleTest\App.cs 67 Active
Error CS0103 The name 'Settings' does not exist in the current context SimpleTest D:\Users\Donald\Source\Repos\SimpleTest\SimpleTest\SimpleTest\App.cs 220 Active
Error CS0103 The name 'Settings' does not exist in the current context SimpleTest D:\Users\Donald\Source\Repos\SimpleTest\SimpleTest\SimpleTest\App.cs 224 Active
Error CS0103 The name 'ApiKey' does not exist in the current context SimpleTest D:\Users\Donald\Source\Repos\SimpleTest\SimpleTest\SimpleTest\App.cs 232 Active
Error CS0103 The name 'Settings' does not exist in the current context SimpleTest D:\Users\Donald\Source\Repos\SimpleTest\SimpleTest\SimpleTest\App.cs 261 Active
Error CS0103 The name 'Settings' does not exist in the current context SimpleTest D:\Users\Donald\Source\Repos\SimpleTest\SimpleTest\SimpleTest\App.cs 262 Active
Error CS0103 The name 'Settings' does not exist in the current context SimpleTest D:\Users\Donald\Source\Repos\SimpleTest\SimpleTest\SimpleTest\App.cs 264 Active
Error CS1061 'FullAccount' does not contain a definition for 'RootInfo' and no accessible extension method 'RootInfo' accepting a first argument of type 'FullAccount' could be found (are you missing a using directive or an assembly reference?) SimpleTest D:\Users\Donald\Source\Repos\SimpleTest\SimpleTest\SimpleTest\App.cs 343 Active
Error CS1061 'DropboxClient' does not contain a definition for 'WithPathRoot' and no accessible extension method 'WithPathRoot' accepting a first argument of type 'DropboxClient' could be found (are you missing a using directive or an assembly reference?) SimpleTest D:\Users\Donald\Source\Repos\SimpleTest\SimpleTest\SimpleTest\App.cs 352 Active
Error CS0426 The type name 'Root' does not exist in the type 'PathRoot' SimpleTest D:\Users\Donald\Source\Repos\SimpleTest\SimpleTest\SimpleTest\App.cs 352 Active
Error CS1061 'FullAccount' does not contain a definition for 'RootInfo' and no accessible extension method 'RootInfo' accepting a first argument of type 'FullAccount' could be found (are you missing a using directive or an assembly reference?) SimpleTest D:\Users\Donald\Source\Repos\SimpleTest\SimpleTest\SimpleTest\App.cs 352 Active
Error CS0246 The type or namespace name 'PathRootException' could not be found (are you missing a using directive or an assembly reference?) SimpleTest D:\Users\Donald\Source\Repos\SimpleTest\SimpleTest\SimpleTest\App.cs 355 Active

Highlighted

Re: RespondPageWithJSRedirect() - where is this defined?

Dropboxer

I see, thanks. I do recommend starting from the unmodified SimpleTest on a supported platform as a reference, as that should work out of the box with no modifications (beyond plugging in your own app key). That's what I tested, and it worked for me. 

Anyway, unfortunately the SDK isn't officially supported in Xamarin, so we can't offer support for that platform. I'll send this along as a feature request for official support for that though. We can't officially support that third party library either of course, as that's maintained by a third party.

Highlighted

Re: RespondPageWithJSRedirect() - where is this defined?

Collaborator | Level 8

Dropbox won't let me register another app called SimpleTest so that I can get my own apikey for it - can you supply the apikey for it? Or if I use one I have already, will that work if the names don't match? I've tried to work around this restriction, with no success so far. i.e. tried to clone SimpleTest, calling it something different in the process, however when I click "fork", it forks the whole .net library, not just SimpleTest itself. Not sure how to get around this restriction on unique app names (or that it won't let me fork just that directory).

Highlighted

Re: RespondPageWithJSRedirect() - where is this defined?

Dropboxer

The reason you cannot register a duplicate Dropbox App with the same name is because Dropbox requires App names be unique.  I do not believe you need to create a new Dropbox app for your use case.  It is okay if the name of your app registered with Dropbox and the name of the .NET project do not match.

Highlighted

Re: RespondPageWithJSRedirect() - where is this defined?

Collaborator | Level 8

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?

 

Highlighted

Re: RespondPageWithJSRedirect() - where is this defined?

Dropboxer

Thanks 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.)

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?