Я пытаюсь создать лист Google с помощью Java Springboot. Несмотря на то, что моя квота запросов не превышена, я получаю исключение 429 «Слишком много запросов».
Изображение ошибки: (https://i.sstatic.net/m1axt0Ds.png)
Это мой код:
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.util.store.FileDataStoreFactory;
import com.google.api.services.sheets.v4.Sheets;
import com.google.api.services.sheets.v4.SheetsScopes;
import com.google.api.services.sheets.v4.model.Spreadsheet;
import com.google.api.services.sheets.v4.model.SpreadsheetProperties;
import com.google.api.services.sheets.v4.model.ValueRange;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.GeneralSecurityException;
import java.util.Collections;
import java.util.List;
public class SheetsQuickstart {
private static final String APPLICATION_NAME = "Google Sheets API Java Quickstart";
private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
private static final String TOKENS_DIRECTORY_PATH = "tokens";
private static final List SCOPES =
Collections.singletonList(SheetsScopes.SPREADSHEETS);
private static final String GOOGLE_APPLICATION_CREDENTIALS = "/google-sheets-client-secret.json";
private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT)
throws IOException {
// Load client secrets.
InputStream in = SheetsQuickstart.class.getResourceAsStream(GOOGLE_APPLICATION_CREDENTIALS);
if (in == null) {
throw new FileNotFoundException("Resource not found: " + GOOGLE_APPLICATION_CREDENTIALS);
}
GoogleClientSecrets clientSecrets =
GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
.setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
.setAccessType("offline")
.build();
LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
public static void getData() throws GeneralSecurityException, IOException {
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
final String spreadsheetId = "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms";
final String range = "Class Data!A2:E";
Sheets service =
new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
.setApplicationName(APPLICATION_NAME)
.build();
ValueRange response = service.spreadsheets().values()
.get(spreadsheetId, range)
.execute();
List values = response.getValues();
if (values == null || values.isEmpty()) {
System.out.println("No data found.");
} else {
System.out.println("Name, Major");
for (List row : values) {
// Print columns A and E, which correspond to indices 0 and 4.
System.out.printf("%s, %s\n", row.get(0), row.get(4));
}
}
}
public static String createSpreadsheet(String title) throws IOException, GeneralSecurityException {
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
Sheets service = new Sheets.Builder(new NetHttpTransport(),
JSON_FACTORY,
getCredentials(HTTP_TRANSPORT))
.setApplicationName("Sheets samples")
.build();
Spreadsheet spreadsheet = new Spreadsheet()
.setProperties(new SpreadsheetProperties()
.setTitle(title));
spreadsheet = service.spreadsheets().create(spreadsheet)
.setFields("spreadsheetId")
.execute();
System.out.println("Spreadsheet ID: " + spreadsheet.getSpreadsheetId());
return spreadsheet.getSpreadsheetId();
}
public static void main(String... args) throws IOException, GeneralSecurityException {
getData();
createSpreadsheet("hi");
}
}
Это метрики запросов облачной консоли, а также изображение квот и ограничений для справки.
Здесь мы видим, что их было всего 8 < сильные>createSpreadsheet запросы и 9 запросов get.
Еще одна вещь, на которую следует обратить внимание: все 9 запросов getValues были успешными, но все 8 запросов createSpreadsheet завершились неудачно. с этой ошибкой.
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 429 Too Many Requests
{
"code": 429,
"errors": [
{
"domain": "global",
"message": "Resource has been exhausted (e.g. check quota).",
"reason": "rateLimitExceeded"
}
],
"message": "Resource has been exhausted (e.g. check quota).",
"status": "RESOURCE_EXHAUSTED"
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... -check-quo
Google Sheets API v4 – Получение 429 [Ресурс исчерпан (например, проверка квоты)] во время создания электронной таблицы ⇐ JAVA
Программисты JAVA общаются здесь
1722591971
Anonymous
Я пытаюсь создать лист Google с помощью Java Springboot. Несмотря на то, что моя квота запросов не превышена, я получаю исключение 429 «Слишком много запросов».
Изображение ошибки: (https://i.sstatic.net/m1axt0Ds.png)
Это мой код:
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.util.store.FileDataStoreFactory;
import com.google.api.services.sheets.v4.Sheets;
import com.google.api.services.sheets.v4.SheetsScopes;
import com.google.api.services.sheets.v4.model.Spreadsheet;
import com.google.api.services.sheets.v4.model.SpreadsheetProperties;
import com.google.api.services.sheets.v4.model.ValueRange;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.GeneralSecurityException;
import java.util.Collections;
import java.util.List;
public class SheetsQuickstart {
private static final String APPLICATION_NAME = "Google Sheets API Java Quickstart";
private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
private static final String TOKENS_DIRECTORY_PATH = "tokens";
private static final List SCOPES =
Collections.singletonList(SheetsScopes.SPREADSHEETS);
private static final String GOOGLE_APPLICATION_CREDENTIALS = "/google-sheets-client-secret.json";
private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT)
throws IOException {
// Load client secrets.
InputStream in = SheetsQuickstart.class.getResourceAsStream(GOOGLE_APPLICATION_CREDENTIALS);
if (in == null) {
throw new FileNotFoundException("Resource not found: " + GOOGLE_APPLICATION_CREDENTIALS);
}
GoogleClientSecrets clientSecrets =
GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
.setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
.setAccessType("offline")
.build();
LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
public static void getData() throws GeneralSecurityException, IOException {
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
final String spreadsheetId = "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms";
final String range = "Class Data!A2:E";
Sheets service =
new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
.setApplicationName(APPLICATION_NAME)
.build();
ValueRange response = service.spreadsheets().values()
.get(spreadsheetId, range)
.execute();
List values = response.getValues();
if (values == null || values.isEmpty()) {
System.out.println("No data found.");
} else {
System.out.println("Name, Major");
for (List row : values) {
// Print columns A and E, which correspond to indices 0 and 4.
System.out.printf("%s, %s\n", row.get(0), row.get(4));
}
}
}
public static String createSpreadsheet(String title) throws IOException, GeneralSecurityException {
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
Sheets service = new Sheets.Builder(new NetHttpTransport(),
JSON_FACTORY,
getCredentials(HTTP_TRANSPORT))
.setApplicationName("Sheets samples")
.build();
Spreadsheet spreadsheet = new Spreadsheet()
.setProperties(new SpreadsheetProperties()
.setTitle(title));
spreadsheet = service.spreadsheets().create(spreadsheet)
.setFields("spreadsheetId")
.execute();
System.out.println("Spreadsheet ID: " + spreadsheet.getSpreadsheetId());
return spreadsheet.getSpreadsheetId();
}
public static void main(String... args) throws IOException, GeneralSecurityException {
getData();
createSpreadsheet("hi");
}
}
Это метрики запросов облачной консоли, а также изображение квот и ограничений для справки.
Здесь мы видим, что их было всего 8 < сильные>createSpreadsheet запросы и 9 запросов get.
Еще одна вещь, на которую следует обратить внимание: все 9 запросов getValues были успешными, но все 8 запросов [b]createSpreadsheet[/b] завершились неудачно. с этой ошибкой.
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 429 Too Many Requests
{
"code": 429,
"errors": [
{
"domain": "global",
"message": "Resource has been exhausted (e.g. check quota).",
"reason": "rateLimitExceeded"
}
],
"message": "Resource has been exhausted (e.g. check quota).",
"status": "RESOURCE_EXHAUSTED"
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78681951/google-sheets-api-v4-getting-429-resource-has-been-exhausted-e-g-check-quo[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия