2013-10-26 49 views
2

我試圖運行此以下行如何在java中創建一個集合<String>出單個字符串?

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(",")));

但是有一個更簡單的方法發送適當類型的參數?

+0

不,它不是。 –

回答

3

在DriveScopes的所有字符串常量的值(the current version of the API!)是單範圍鍵,而不是逗號分隔的列表。所以,你應該創建任何合適的集合 - 這是一個很好的方式來創建Java的大小1的集合:

Collections.singleton(DriveScopes.DRIVE) 
+0

但不會逗號分隔的一個項目集合看起來完全一樣嗎? '{item1}' –

+0

您發送的API中的哪一行可以教給我'單個範圍鍵'? –

+0

'公共靜態最後絃樂\t DRIVE \t「https://www.googleapis.com/auth/drive」'< - 沒有在該字符串常量逗號 - 這是一個單獨的範圍鍵。和其他所有一樣。 –

相關問題