Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dropbox核心API JAVA授权代码_Java_Connection_Dropbox_Dropbox Api - Fatal编程技术网

Dropbox核心API JAVA授权代码

Dropbox核心API JAVA授权代码,java,connection,dropbox,dropbox-api,Java,Connection,Dropbox,Dropbox Api,使用dropbox,我可以上传一个文件 但是,我的问题与此完全相同,即,一旦我有了授权码并注释掉用户授权行,这样我就不必每次使用dropbox时都手动重新授权批准,我会出现以下错误: Exception in thread "main" com.dropbox.core.DbxException$BadRequest: {"error_description": "code has already been used", "error": "invalid_grant"} 或 我确信我有正确的

使用dropbox,我可以上传一个文件

但是,我的问题与此完全相同,即,一旦我有了授权码并注释掉用户授权行,这样我就不必每次使用dropbox时都手动重新授权批准,我会出现以下错误:

Exception in thread "main" com.dropbox.core.DbxException$BadRequest: {"error_description": "code has already been used", "error": "invalid_grant"}

我确信我有正确的授权码

我希望我遗漏了一些东西,否则,如果每次使用API时都需要人工干预,那么API有什么意义呢

编辑:我的确切代码(密钥已被置乱)


您应该存储和重用访问令牌,而不是授权代码

所以在做了一次之后:

String accessToken=authFinish.accessToken

你应该把整个东西换成

String accessToken=”“


顺便说一句,如果你只需要一个访问令牌为你自己的帐户,你可以生成一个点击按钮!请参阅。

您没有正确使用访问令牌。请粘贴一些有关如何使用令牌的代码。向我们展示整个dropbox代码lines@devaldcool谢谢你的时间,我张贴在编辑下我的代码。
Exception in thread "main" com.dropbox.core.DbxException$BadRequest: {"error_description": "code has expired (within the last hour)", "error": "invalid_grant"}
import com.dropbox.core.*;
import java.io.*;
import java.util.Locale;

public class DropboxUpload {
    public static void main(String[] args) throws IOException, DbxException {
        // Get your app key and secret from the Dropbox developers website.
        final String APP_KEY = "2po9b49whx74h67";
        final String APP_SECRET = "m98f734hnr92kmh";

        DbxAppInfo appInfo = new DbxAppInfo(APP_KEY, APP_SECRET);

        DbxRequestConfig config = new DbxRequestConfig("JavaTutorial/1.0",
            Locale.getDefault().toString());
        DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);

        // Have the user sign in and authorize your app.
        //String authorizeUrl = webAuth.start();
        //System.out.println("1. Go to: " + authorizeUrl);
        //System.out.println("2. Click \"Allow\" (you might have to log in first)");
        //System.out.println("3. Copy the authorization code.");
        //String code = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();

        DbxAuthFinish authFinish = webAuth.finish("VtwxzitUoI8DDDLx0PlLut5Gjpw3");
        String accessToken = authFinish.accessToken;

        DbxClient client = new DbxClient(config, accessToken);

        System.out.println("Linked account: " + client.getAccountInfo().displayName);

        File inputFile = new File("/home/dropboxuser/Documents/test.txt");
        FileInputStream inputStream = new FileInputStream(inputFile);
        try {
            DbxEntry.File uploadedFile = client.uploadFile("/Public/test.txt",
                DbxWriteMode.add(), inputFile.length(), inputStream);
            System.out.println("Uploaded: " + uploadedFile.toString());
        } finally {
            inputStream.close();
        }

        DbxEntry.WithChildren listing = client.getMetadataWithChildren("/");
        System.out.println("Files in the root path:");
        for (DbxEntry child : listing.children) {
            System.out.println("    " + child.name + ": " + child.toString());
        }

        FileOutputStream outputStream = new FileOutputStream("test.txt");
        try {
            DbxEntry.File downloadedFile = client.getFile("/Public/test.txt", null,
                outputStream);
            System.out.println("Metadata: " + downloadedFile.toString());
        } finally {
            outputStream.close();
        }
    }
}