c# - Blazor Wasm(无 WebApi)Google 表格授权
问题描述
我想创建一个 Blazor Wasm 应用程序来访问 Google 表格文档。按照指南(https://developers.google.com/sheets/api/quickstart/dotnet),我有以下代码:
public static class GoogleSheetsService
{
public static async void Authenticate()
{
string[] scopes = { SheetsService.Scope.Spreadsheets };
var applicationName = "Google Sheets API .NET Quickstart";
var clientsecrets = new ClientSecrets
{
ClientId = "....apps.googleusercontent.com",
ClientSecret = "..."
};
var credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
clientsecrets,
scopes,
"user",
CancellationToken.None,
new MyDataStore());
// Create Google Sheets API service.
var service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = applicationName,
});
....
}
}
由于文件处理,我创建了自己的 IDataStore 实现作为 MyDataStore。(我更喜欢将给定的凭据保存在本地存储中,避免使用文件)。
运行代码时会出现以下错误(只是第一部分,要长得多):
blazor.webassembly.js:1 未处理的异常:
blazor.webassembly.js:1 System.PlatformNotSupportedException:此平台不支持操作。
在 System.Net.Sockets.Socket..ctor (System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType) <0x3028760 + 0x0003c> in :0
blazor.webassembly.js:1 在 System.Net.Sockets.TcpListener..ctor (System.Net.IPAddress localaddr, System.Int32 端口) <0x301c470 + 0x0006e> in :0
所以我的问题是,出了什么问题,是否可以仅使用 Wasm 以这种方式或任何其他方式访问 Google 表格文档?
解决方案
推荐阅读
- javascript - 在 javascript 中设置 Cookie 并在 PHP 中读取它
- google-app-engine - 带有 Google 应用引擎的 Eureka Server(主机名问题)
- python - 划分为具有单个数据的子列表中的列表
- r - 使用递增变量循环并改变多个列
- jasper-reports - 生成碧玉报告时的空行 6.11
- google-search-console - 谷歌站点地图:错误
- scikit-learn - SVR 超参数选择和可视化
- json - 如果 json 无效,如何将字符串转换为 json 或映射以在 dart 中配对
- docker - Docker - 错误:无法从非 TTY 设备执行交互式登录(GCP 服务帐户)
- ionic-framework - 将项目从 Windows 10 复制到 MacOS Catalina 并使用 Visual Studio Code - Ionic & Angular 打开