简体   繁体   English

无法重定向到DropBox登录页面

[英]Unable to redirect to DropBox login page

I am integrating DropBox in my Java based application. 我正在将DropBox集成到基于Java的应用程序中。 The following piece of code, when executed in stand alone mode, works fine. 在独立模式下执行时,以下代码段可以正常工作。

private String APP_KEY = "APP_KEY";
private String APP_SECRET = "APP_SECRET";
private AccessType ACCESS_TYPE = AccessType.APP_FOLDER;

AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
WebAuthSession session = new WebAuthSession(appKeys, ACCESS_TYPE);


WebAuthInfo authInfo = session.getAuthInfo("callbackURL");

RequestTokenPair pair = authInfo.requestTokenPair;
String url = authInfo.url;
Desktop.getDesktop().browse(URL(url).toURI());
session.retrieveWebAccessToken(pair);

AccessTokenPair tokens = session.getAccessTokenPair();

In stand alone mode this piece of code redirects me to the DropBox log-in page, the user will authorize the app and then the control is back on to the page mentioned in the "callbackURL". 在独立模式下,这段代码将我重定向到DropBox登录页面,用户将授权该应用程序,然后控件返回到“ callbackURL”中提到的页面。

I use the same patch when i am actually running my site. 我实际上在运行网站时使用相同的补丁程序。 I have a link saying "Link to DropBox now." 我有一个链接,显示“现在链接到DropBox”。 On clicking the link, the control is passed to the server via a REST call to execute the above code. 单击链接后,控件将通过REST调用传递到服务器以执行上述代码。 But it gets stuck at the line of code which says, 但是它卡在代码行中,

Desktop.getDesktop().browse(URL(url).toURI());

when all the parameters required to get the authInfo() are properly passed. 当正确获取获取authInfo()所需的所有参数时。

I am not able to determine where i am going wrong. 我无法确定我要去哪里。 Any help will be appreciated. 任何帮助将不胜感激。

Since your is a web-application you cannot call Desktop.getDesktop() (which is meaningful only in the context of a desktop-application). 由于您是Web应用程序,因此无法调用Desktop.getDesktop() (仅在桌面应用程序的上下文中才有意义)。

You should redirect the user to Dropbox (namely to the URL you receive in the statement authInfo.url ), using something like response.sendRedirect("callbackURL"); 您应该使用response.sendRedirect("callbackURL");类的方法将用户重定向到Dropbox(即,您在authInfo.url语句中收到的URL response.sendRedirect("callbackURL"); or using JavaScript on the client-side to set the href of a link. 或在客户端使用JavaScript设置链接的href

Then, Dropbox will redirect the user back to your app (namely to the URL you specified as "callbackURL"), where you should have a servlet parse Dropbox's response ( more info here - take a look at the "RETURNS" section) and then acquire the _access_token_ ( as described here ). 然后,Dropbox会将用户重定向到您的应用程序(即您指定为“ callbackURL”的URL),在那里您应该有一个servlet解析Dropbox的响应( 更多信息,请在“ RETURNS”部分中查看),然后获取_access_token_( 如此处所述 )。
(At that point you would probably want to store it somewhere (eg in the session-scope) along with the rest of the necessary data.) (那时,您可能希望将其与其余必要数据一起存储在某个位置(例如,在会话范围内)。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM