Error in updating rows Google Sheets API
I try to update rows in Google Sheets, but have error 403
Request had insufficient authentication scopes. [403] Errors [Message[Request had insufficient authentication scopes.] Location[ - ] Reason[forbidden] Domain[global]]
`
using (var stream =
new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/sheets.googleapis.com-dotnet-quickstart.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
// Create Google Sheets API service.
var service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
List<object> list1 = new List<object>() { "Item", "Cost", "Stocked", "Ship Date" };
List<object> list2 = new List<object>() { "Wheel", "$20.50", "4", "3/1/2016" };
List<object> list3 = new List<object>() { "Door", "$15", "2", "3/15/2016" };
List<object> list4 = new List<object>() { "Engine", "$100", "1", "30/20/2016" };
List<object> list5 = new List<object>() { "Totals", "=SUM(B2:B4)", "=SUM(C2:C4)", "=MAX(D2:D4)" };
IList<IList<Object>> list = new List<IList<Object>>() { list1, list2, list3, list4, list5 };
var range = "Sheet1!A1:D5";
ValueRange VRange = new ValueRange();
VRange.Range = range;
VRange.Values = list;
VRange.MajorDimension = "ROWS";
SpreadsheetsResource.ValuesResource.UpdateRequest upd = service.Spreadsheets.Values.Update(VRange, spreadsheetId, range);
upd.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.RAW;
var response = upd.Execute();
Console.WriteLine(response.UpdatedRows);`
So what is Scopes here? Please note that we (the people likely to read this issue) are not Sheets API experts, so much as experts in the code generation for the .NET client libraries. If this ends up in the subtleties of which scopes are required, you may end up being better off asking in a Sheets-specific community such as https://developers.google.com/google-apps/spreadsheets/
Not an issue with the client.
@bezobraz1e make sure you use the 'SheetsService.Scope.Spreadsheets' scope instead of 'SheetsService.Scope.SpreadsheetsReadOnly'. If you've already authenticated with the read only scope, you have to go to the folder where you stored the token and delete it to re-authenticate in the new scope (in your case "Documents/.credentials/sheets.googleapis.com-dotnet-quickstart.json").
This should be closed.
Closing - but @bezobraz1e, if you still have problems (and you think it is a .NET API issue), feel free to ping me to reopen.
Please remove FileDataStore .
credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None //, //new FileDataStore(credPath, true) ).Result;
just do and then its working .