C#使用ServiceAccount实现的谷歌电子表格服务
GDataRequestFactory中的“我的应用程序用户代理”是什么。我已经完成了上面提到的代码,但仍然没有得到电子表格。我无法从谷歌文档中访问电子表格数据C#使用ServiceAccount实现的谷歌电子表格服务,c#,google-api,google-spreadsheet-api,service-accounts,C#,Google Api,Google Spreadsheet Api,Service Accounts,GDataRequestFactory中的“我的应用程序用户代理”是什么。我已经完成了上面提到的代码,但仍然没有得到电子表格。我无法从谷歌文档中访问电子表格数据 if (!File.Exists(keyFilePath)) { Console.WriteLine("An Error occurred - Key file does not exist"); return null; } //Google Drive scopes Docu
if (!File.Exists(keyFilePath))
{
Console.WriteLine("An Error occurred - Key file does not exist");
return null;
}
//Google Drive scopes Documentation: https://developers.google.com/drive/web/scopes
string[] scopes = new string[] { "https://spreadsheets.google.com/feeds", "https://docs.google.com/feeds" }; // modify your app scripts
var certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.Exportable);
try
{
var serviceAccountCredentialInitializer =
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { "https://spreadsheets.google.com/feeds" }
}.FromCertificate(certificate);
var credential = new ServiceAccountCredential(serviceAccountCredentialInitializer);
//if (!credential.RequestAccessTokenAsync(System.Threading.CancellationToken.None).Result)
// throw new InvalidOperationException("Access token request failed.");
credential.RequestAccessTokenAsync(System.Threading.CancellationToken.None).Wait();
var requestFactory = new GDataRequestFactory("My App User Agent");
requestFactory.CustomHeaders.Add("Authorization: Bearer " + credential.Token.AccessToken);
SpreadsheetsService service = new SpreadsheetsService("CallLog");
service.RequestFactory = requestFactory;
SpreadsheetQuery query = new SpreadsheetQue`enter code here`ry(); //do the job as you done it before
SpreadsheetFeed feed = service.Query(query);
您看到的错误是什么?您的代码不清楚:电子表格查询=新建电子表格
在此处输入代码
ry();这是什么意思?我把OAuth2设置成这样。。您可以尝试使用gridspree.io之类的工具来检查内容。您知道什么是用户代理吗?useagent和ApplicationName之间有什么区别?