首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于CloudRail的Dropbox认证

基于CloudRail的Dropbox认证
EN

Stack Overflow用户
提问于 2016-01-18 13:36:46
回答 1查看 537关注 0票数 2

我尝试过使用CloudRail集成Dropbox,但遇到了一些问题:

  1. 如何通过CloudRail API检索访问令牌
  2. 在简单的控制台应用程序中编码时,redirecURI是什么?
  3. 最后,我需要在System.out.print方法中实现onSuccess

以下是我尝试过的:

代码语言:javascript
复制
package com.cloudrail.userInterface;

import java.io.InputStream;
import com.cloudrail.auth.UriRedirectListener;
import com.cloudrail.auth.UriView;
import com.cloudrail.auth.uriRedirect.HttpsServerRedirectListener;
import com.cloudrail.auth.uriView.LocalUriCaller;
import com.cloudrail.exception.CloudRailException;
import com.cloudrail.userInterface.CloudDownload.DropboxDLResponseListener;

public class CloudDownloadTest {

    final static String dropboxID = "someID"; // Put your Dropbox client id
    final static String dropboxSecret = "someSecret"; // Put your Dropbox client secret
    final static String dropboxCloudFilePath = "afile.txt"; // Put the path to the file that should be downloaded from Dropbox
    final static String dropboxDiskFilePath = "somePath/CopiedDPBFile"; // Put the path the Dropbox file should be downloaded to



//  I have questions about redirectURI - What is it how can I figure it out or take from somwehere.
//  Can I just give the hhtps://www.dropbox.com or it should be the site url where I integrate the API.
    final static String redirectURI = "soemURIString";
    final static String state = Long.toHexString(Double.doubleToLongBits(Math.random())); // Random state to prevent CSRF
    // First argument is a dummy SSL context for local testing
    final static UriRedirectListener uriRedirectListener = new HttpsServerRedirectListener(Helper.getDummyContext(), 8080);
    final static UriView localUriCaller = new LocalUriCaller(); // Opens URLs in the local browser

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        CloudDownload cloudDownload = new CloudDownload(dropboxID, redirectURI, dropboxSecret, state);

        cloudDownload.init_DropboxContentAPI_Auth(localUriCaller, uriRedirectListener, new AccessTokenCallback() {

            @Override
            public void onError(CloudRailException arg0) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onToken(String arg0) {
                // TODO Auto-generated method stub
//              How to retrieve the access token with CloudRail
                cloudDownload.dropboxDL(dropboxCloudFilePath, "retrievedAccessToken", new DropboxDLResponseListener() {

                    @Override
                    public void onSuccess(InputStream file) {
                        // TODO Auto-generated method stub
//                      what I need to print out simple Hello work in console
                        System.out.println("Hello");
                    }

                    @Override
                    public void onProgress(double percentFinished) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onError(CloudRailException error) {
                        // TODO Auto-generated method stub
                        error.printStackTrace();
                    }
                });
            }
        });
        cloudDownload.start_DropboxContentAPI_Auth();

    }
}
EN

回答 1

Stack Overflow用户

发布于 2016-01-18 14:25:58

对于第一个问题: CloudRail实际上完成了为您提供身份验证的可能性的工作,您的代码已经非常接近了。您提供的AccessTokenCallback类在其onToken方法中接收访问令牌,作为用户成功身份验证后的参数。这意味着您必须按以下方式更改代码:

代码语言:javascript
复制
public void onToken(String arg0) {
    cloudDownload.dropboxDL(dropboxCloudFilePath, arg0, new DropboxDLResponseListener() { 
        ...

对于第二个问题,OAuth 2.0的重定向URI是身份验证服务器在身份验证成功后重定向到的URI。它通常是指向服务器上特定端点的URL。对于本地运行的简单控制台应用程序,重定向到localhost就足够了。由于您的URIRedirectListener在端口8080上设置了一个服务器来侦听这样的重定向,所以您必须将

https://localhost:8080

作为重定向URI。

为了解决您的第三点,假设您修复了另外两件事情,这应该可以正常工作。

当然,在尝试代码之前,您必须记住要为客户端标识符和机密设置有效值。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34856101

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档