我目前正试图使用Google Sheets v4 API简单地删除我的Google Spreadsheet中的一行。(Android/Java)Google表格v4 isUserRecoverableError状态:NEED_PERMISSION
这里是我使用的代码:
private void deleteRow()
{
List<Request> requests = new ArrayList<>();
DeleteDimensionRequest deleteDimensionRequest = new DeleteDimensionRequest();
DimensionRange dimensionRange = new DimensionRange();
dimensionRange.setStartIndex(14);
dimensionRange.setEndIndex(15);
deleteDimensionRequest.setRange(dimensionRange);
requests.add(new Request()
.setDeleteDimension(deleteDimensionRequest)
);
BatchUpdateSpreadsheetRequest batchUpdateRequest = new BatchUpdateSpreadsheetRequest()
.setRequests(requests);
try
{
mService.spreadsheets().batchUpdate("Spreadsheet_ID", batchUpdateRequest).execute();
}
catch(IOException e)
{
e.printStackTrace();
}
}
错误这个功能让我的是:
08-14 15:47:10.818 26956-27285/com.xxx.xxxxx.xxxxxxxx
W/GoogleAuthUtil: isUserRecoverableError status: NEED_PERMISSION
在我的其他类文件,我已经指出的权限范围,包括驱动器和电子表格。
在Java快速入门...
public static Credential authorize() throws IOException {
// Load client secrets.
InputStream in =
SheetsQuickstart.class.getResourceAsStream("/client_secret.json");
GoogleClientSecrets clientSecrets =
GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
// Build flow and trigger user authorization request.
GoogleAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
.setDataStoreFactory(DATA_STORE_FACTORY)
.setAccessType("offline")
.build();
Credential credential = new AuthorizationCodeInstalledApp(
flow, new LocalServerReceiver()).authorize("user");
System.out.println(
"Credentials saved to " + DATA_STORE_DIR.getAbsolutePath());
return credential;
}
这是除了由Android的快速启动提供的一个排序誓言证书的那我需要包括?
您是否在范围之外还包含有效的oauth凭证? (另外,由by开始的范围是包含的,并且结束范围是独占的,因此要求删除[14,14]将最终删除任何内容。如果你想删除第14行,你想要[14,15]。) –
谢谢你的回复Sam。其余代码仅仅是示例快速入门... mCredential = GoogleAccountCredential.usingOAuth2( getApplicationContext(),Arrays.asList(SCOPES)) 。setBackOff(new ExponentialBackOff());我不确定如何包含另一个有效的宣誓证书......我需要某种API密钥吗? – LinearM