[英]Not able to access spreadsheet using google spreadsheet API
我在嘗試訪問已創建的電子表格的地方有此代碼。
public class ExpressionExample {
private static URL cellFeedUrl;
public static final String SPREADSHEET_URL = "https://spreadsheets.google.com/feeds/spreadsheets/private/full/1QWX-zOkBe36M7oC9sn6z8ZuccGt7Wg-IFwtynn379kM";
public static void main(String[] args) throws Exception {
File p12 = new File("key.p12");
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
String[] SCOPESArray = { SPREADSHEET_URL };
final List SCOPES = Arrays.asList(SCOPESArray);
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId("XXXX@developer.gserviceaccount.com")
.setServiceAccountScopes(SCOPES)
.setServiceAccountPrivateKeyFromP12File(p12).build();
SpreadsheetService service = new SpreadsheetService("new data service ");
service.setOAuth2Credentials(credential);
URL metafeedUrl = new URL(SPREADSHEET_URL);
SpreadsheetEntry spreadsheet = service.getEntry(metafeedUrl,
SpreadsheetEntry.class);
WorksheetEntry sheet = ((WorksheetEntry) spreadsheet.getWorksheets()
.get(0));
cellFeedUrl = spreadsheet.getWorksheets().get(0).getCellFeedUrl();
CellEntry cellA1 = new CellEntry(1, 1, "3");
CellEntry cellB1 = new CellEntry(1, 2, "high mech");
String line = "=IF(A1<5,IF(B1={\"high mech\",\"low mech\",\"mid mech\"},10,IF(B1=\"electronic\",20,0)),IF(A1>=5,IF(B1=\"electronic\",40,0),0)) ";
CellEntry cellc1 = new CellEntry(1, 3, line);
service.insert(cellFeedUrl, cellA1);
service.insert(cellFeedUrl, cellB1);
service.insert(cellFeedUrl, cellc1);
ExpressionExample e = new ExpressionExample();
e.printCell(cellA1);
e.printCell(cellB1);
e.printCell(cellc1);
CellQuery query = new CellQuery(cellFeedUrl);
query.setMinimumRow(1);
query.setMaximumRow(1);
query.setMinimumCol(3);
query.setMaximumCol(3);
CellFeed feed = service.query(query, CellFeed.class);
System.out.println(feed.getEntries().indexOf(cellc1));
for (CellEntry entry : feed.getEntries()) {
e.printCell(entry);
}
}
public void printCell(CellEntry cell) {
// String shortId = cell.getId().substring(cell.getId().lastIndexOf('/')
// + 1);
System.out.println(" -- Cell(" + "/" + ") formula("
+ cell.getCell().getInputValue() + ") numeric("
+ cell.getCell().getNumericValue() + ") value("
+ cell.getCell().getValue() + ")");
}
}
執行程序時出現以下錯誤:
Exception in thread "main" ResourceNotFoundException: Not Found Entry not found
任何幫助,將不勝感激。
我認為用於獲取條目的電子表格網址應為:
"https://spreadsheets.google.com/feeds/spreadsheets/" + file Id
嘗試更改,看看是否可以消除該錯誤。
另請檢查此以獲取更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.