我尝试过使用CloudRail集成Dropbox,但遇到了一些问题:
System.out.print方法中实现onSuccess。以下是我尝试过的:
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();
}
}发布于 2016-01-18 14:25:58
对于第一个问题: CloudRail实际上完成了为您提供身份验证的可能性的工作,您的代码已经非常接近了。您提供的AccessTokenCallback类在其onToken方法中接收访问令牌,作为用户成功身份验证后的参数。这意味着您必须按以下方式更改代码:
public void onToken(String arg0) {
cloudDownload.dropboxDL(dropboxCloudFilePath, arg0, new DropboxDLResponseListener() {
...对于第二个问题,OAuth 2.0的重定向URI是身份验证服务器在身份验证成功后重定向到的URI。它通常是指向服务器上特定端点的URL。对于本地运行的简单控制台应用程序,重定向到localhost就足够了。由于您的URIRedirectListener在端口8080上设置了一个服务器来侦听这样的重定向,所以您必须将
作为重定向URI。
为了解决您的第三点,假设您修复了另外两件事情,这应该可以正常工作。
当然,在尝试代码之前,您必须记住要为客户端标识符和机密设置有效值。
https://stackoverflow.com/questions/34856101
复制相似问题