gpt4 book ai didi

json - 使用Google Sheets API

转载 作者:行者123 更新时间:2023-12-01 16:09:06 25 4
gpt4 key购买 nike

我正在尝试将Xamarin Forms与Google Sheets API配合使用,但是我遇到了读取client_secret.json文件的问题,该文件与使用.NET进行编程时一样,需要通过Google进行身份验证。
执行以下行时:

using (var stream =
new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{ ... }

我收到一条错误消息,显示找不到文件client_secret.json。我将文件的属性放入解决方案中,使用“始终复制”(Always Copy)选项将其复制到目录中,但是这样做不走运。 (我正在使用Visual Studio 2017)。

有人可以帮我解决这个问题吗?谢谢。

更新:
我使用的代码如下(任何帮助将不胜感激):
        AssetManager assets = Android.App.Application.Context.Assets;
var path = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), @"client_secret.json");
using (var asset = assets.Open("client_secret.json"))
using (var dest = System.IO.File.Create(path))
asset.CopyTo(dest);

using (var stream = assets.Open(@"client_secret.json"))
{
var secrets = GoogleClientSecrets.Load(stream).Secrets;

string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, "sheets.googleapis.com-dotnet-quickstart.json");

credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}

最佳答案

我也遇到了client_secret.json文件的问题。它所属位置的说明对我不起作用。

因此,我将副本放入主目录的.credentials目录(/user/.credentials)中,然后将副本放入正在执行的应用程序的目录中-两者之一有效。我会尝试将client_secret.json放在其他目录中,直到应用程序找到它为止。

关于json - 使用Google Sheets API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47814921/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com