java - 如何在java中从单个字符串创建集合<String>?

标签 java eclipse google-drive-api

我正在尝试运行以下行

credential = GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE);

并收到此错误:

The method usingOAuth2(Context, Collection<String>) in the type GoogleAccountCredential is not applicable for the arguments (GoogleDriveProxeyActivity, String)

然后我将代码更改为:

credential = GoogleAccountCredential.usingOAuth2(this, Arrays.asList(DriveScopes.DRIVE.split(",")));

但是有没有更简单\更简洁的方法来发送正确类型的参数?

最佳答案

DriveScopes 中的所有字符串常量的值(在 the current version of the API !)都是单个范围键,而不是逗号分隔的列表。因此,您应该创建任何合适的集合 - 这是在 Java 中创建大小为 1 的集合的好方法:

Collections.singleton(DriveScopes.DRIVE)

关于java - 如何在java中从单个字符串创建集合<String>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19611773/

相关文章:

java - 尝试编译基本 JNI 测试代码时 VS2010 出错

java - java中矩阵的逆

android - 在 dandar3 的 eclipse 中打开 android 支持 appcompat 时出错

google-apps-script - 使用工作表 ID 而不是工作表标题查找 Google 表格值(Google Drive Rest API V4)

python - 通过 Google Drive API 访问共享云端硬盘时出现 404 错误

java - 使随机 mac 地址生成器仅生成单播 mac

java - Java -Xprof 输出的解释

android - 带有混淆器的 Ksoap2

java - 通过JUNIT运行程序时如何打印值(用于调试)

java - 使用 Java 和 Google Drive API V3 将文件上传到共享的 Google 云端硬盘位置?