提问者:小点点

线程“main”Java . lang中出现异常错误:未解决的编译问题gdrive [duplicate]


这是我的代码。

我的程序将文件上传到gdrive:

import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse;
import com.google.api.client.http.FileContent;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.DriveScopes;
import com.google.api.services.drive.model.File;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

// main function  
public class DriveCommandLine 
{
// providing id and user 
  private static String CLIENT_ID = "686430-a05tdl7fbkrkuf3cd1029ivhst8rocuo.apps.googleusercontent.com";
  private static String CLIENT_SECRET = "nI-SthRC4UU0P__ow";

  private static String REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob";

  public static void main(String[] args) throws IOException
  {
    HttpTransport httpTransport = new NetHttpTransport();
    JsonFactory jsonFactory = new JacksonFactory();

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory, CLIENT_ID, CLIENT_SECRET, Arrays.asList(DriveScopes.DRIVE)).setAccessType("online").setApprovalPrompt("auto").build();

    String url = flow.newAuthorizationUrl().setRedirectUri(REDIRECT_URI).build();
    System.out.println("Please open the following URL in your browser then type the authorization code:");
    System.out.println("  " + url);
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String code = br.readLine();

    GoogleTokenResponse response = flow.newTokenRequest(code).setRedirectUri(REDIRECT_URI).execute();
    GoogleCredential credential = new GoogleCredential().setFromTokenResponse(response);

    //Create a new authorized API client
    Drive service = new Drive.Builder(httpTransport, jsonFactory, credential).build();

    //Insert a file  
    File body = new File();
    body.setTitle("My document");
    body.setDescription("A test document");
    body.setMimeType("text/plain");

    java.io.File fileContent = new java.io.File("document.txt");
    FileContent mediaContent = new FileContent("text/plain", fileContent);

    File file = service.files().insert(body, mediaContent).execute();
    System.out.println("File ID: " + file.getId());
  }
}

收到错误为:

线程“main”java.lang 中的异常。错误: 未解决的编译问题: 无法将驱动器范围解析为变量 无法将驱动器解析为类型 无法将驱动器解析为类型 无法将文件解析为类型 无法将文件解析为类型

在gdrive。drivecommandline . main(drivecommandline . Java:33)

有人能帮我吗?


共1个答案

匿名用户

假设您在执行应用程序时遇到错误,并且使用Eclipse,这应该可以解决您的问题:

  1. 从构建路径中删除第三方库
  2. 在Android项目中创建一个名为libs
  3. 的文件夹
  4. 将第三方库复制到新创建的文件夹中
  5. 将复制的库添加到生成路径

我记得的是,这些库必须实际存在于Android项目中,才能导出到最终的“应用程序文件”中。