无法解析AuthorizationCodeInstalledApp中的java.awt.Desktop

时间:2018-03-20 12:03:43

标签: authorization youtube-data-api

我正在尝试按照https://developers.google.com/youtube/v3/code_samples/java#authorize_a_request在我的Android应用中登录YouTube 但我遇到了以下错误:

java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/Desktop;


at com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp.browse(AuthorizationCodeInstalledApp.java:129)
at com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp.onAuthorization(AuthorizationCodeInstalledApp.java:113)                                                                             at com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp.authorize(AuthorizationCodeInstalledApp.java:81)

以下是代码:

    public Credential authorize() throws IOException {
            // Load client secrets.
            InputStream in = MainActivity.class.getClassLoader().getResourceAsStream("client_secret.json"); //new FileInputStream("client_secret.json");
            clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader( in ));
            File file = new File(storePath);
            DATA_STORE_FACTORY = new FileDataStoreFactory(file);
            HTTP_TRANSPORT = new com.google.api.client.http.javanet.NetHttpTransport();
            flow = new GoogleAuthorizationCodeFlow.Builder(
                    HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
                    .setDataStoreFactory(DATA_STORE_FACTORY)
                    .setAccessType("offline")
                    .build();

            DataStore<StoredCredential> datastore = DATA_STORE_FACTORY.getDataStore("blank");

            // Build the local server and bind it to port 8080
            LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();

            // Authorize.
            return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
    }

有人可以帮我这个吗? 提前谢谢。

0 个答案:

没有答案