Blazor Wasm(无WebApi)Google表格授权

时间:2020-10-09 20:51:18

标签: google-sheets blazor-webassembly

我想创建一个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,套接字类型, System.Net.Sockets.ProtocolType protocolType)<0x3028760 + 0x0003c>在 :0

System.Net.Sockets.TcpListener..ctor上的

blazor.webassembly.js:1 (System.Net.IPAddress localaddr,System.Int32端口)<0x301c470 + 0x0006e>在:0

所以我的问题是,出了什么问题,是否可以仅使用Wasm以这种方式或任何其他方式访问Google表格文档?

0 个答案:

没有答案