0
我已經實施了一個Google服務帳戶,並將其作爲授權用戶添加到工作表中。Google表格C#不返回所有表格
接下來,我用下面的代碼來訪問表飼料:
const string gUser = "[email protected]";
const string certFile = "CERTFILE.p12";
static void Main(string[] args) {
var certificate = new X509Certificate2(certFile, "notasecret", X509KeyStorageFlags.Exportable);
var serviceAccountCredentialInitializer = new ServiceAccountCredential.Initializer(gUser) {
Scopes = new[] { "https://spreadsheets.google.com/feeds/" }
}.FromCertificate(certificate);
var credential = new ServiceAccountCredential(serviceAccountCredentialInitializer);
if (!credential.RequestAccessTokenAsync(System.Threading.CancellationToken.None).Result)
return;
var requestFactory = new GDataRequestFactory(null);
requestFactory.CustomHeaders.Add("Authorization: Bearer " + credential.Token.AccessToken);
var service = new SpreadsheetsService("MY-SHEETS-SVC") { RequestFactory = requestFactory };
SpreadsheetQuery query = new SpreadsheetQuery();
var sheetFeed = service.Query(query);
Console.WriteLine("Spreadsheet list:");
foreach (var sheet in sheetFeed.Entries) {
Console.WriteLine("\t--" + sheet.Title.Text);
}
Console.ReadLine();
}
但是它並沒有給予儘管服務帳戶的編輯權限返回的任何紙張。我已盡力將服務帳戶添加到Google Apps安全組,但結果沒有變化。在過去創建帳戶(相同的應用程序域等)並授予它在共享設置中的編輯權限是所有必需的。 API是否已更改爲僅需要OAUTH,或者是否存在某種我丟失的設置?