带有 Flutter 的 Google 表格:invalid_grant 无效的 JWT
Googlesheet with Flutter : invalid_grant Invalid JWT
因此,过去 2 小时我一直在寻找解决方案,但我无处可寻。
我已经按照 link 设置 google sheet API 以便将其与 Flutter 一起使用。
我不断收到此错误:
ServerRequestFailedException (Failed to obtain access credentials. Error: invalid_grant Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values in the JWT claim. Status code: 400)
据我所知,这与时间问题有关,但我已确保设备的时间正确 + 在设置中启用了自动设置。
我正在使用 android 模拟器 (Pixel 4 API 27)
这些是显示我的时间设置的 2 张图片:
我的代码:(我在 main 中调用 initSheet())
class SpreadSheet {
static late final gsheets;
static late final spreadsheet;
static Future<bool> initSheet() async {
// TODO: Handle errors (Wrong time....)
gsheets = GSheets(_credentials);
/// link looks like so https://docs.google.com/spreadsheets/d/YOUR_SPREADSHEET_ID/edit#gid=0
/// [YOUR_SPREADSHEET_ID] in the path is the id your need
spreadsheet = await gsheets
.spreadsheet("1t51H_CSHPFoKB7KW_AcGMi3gwyJnecfM_k5wvk4OQ04");
return (spreadsheet == null ? false : true);
}
}
不知何故,代码现在 运行 完美无缺。
我使用了 flutter clean
并且不得不重新下载 gradle-6.9 zip 因为它不知何故被破坏了。
我仍然不知道这是否正是真正修复它的原因,但如果有人再次遇到这个问题,那么值得一试。
因此,过去 2 小时我一直在寻找解决方案,但我无处可寻。 我已经按照 link 设置 google sheet API 以便将其与 Flutter 一起使用。 我不断收到此错误:
ServerRequestFailedException (Failed to obtain access credentials. Error: invalid_grant Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values in the JWT claim. Status code: 400)
据我所知,这与时间问题有关,但我已确保设备的时间正确 + 在设置中启用了自动设置。 我正在使用 android 模拟器 (Pixel 4 API 27)
这些是显示我的时间设置的 2 张图片:
我的代码:(我在 main 中调用 initSheet())
class SpreadSheet {
static late final gsheets;
static late final spreadsheet;
static Future<bool> initSheet() async {
// TODO: Handle errors (Wrong time....)
gsheets = GSheets(_credentials);
/// link looks like so https://docs.google.com/spreadsheets/d/YOUR_SPREADSHEET_ID/edit#gid=0
/// [YOUR_SPREADSHEET_ID] in the path is the id your need
spreadsheet = await gsheets
.spreadsheet("1t51H_CSHPFoKB7KW_AcGMi3gwyJnecfM_k5wvk4OQ04");
return (spreadsheet == null ? false : true);
}
}
不知何故,代码现在 运行 完美无缺。
我使用了 flutter clean
并且不得不重新下载 gradle-6.9 zip 因为它不知何故被破坏了。
我仍然不知道这是否正是真正修复它的原因,但如果有人再次遇到这个问题,那么值得一试。