Johan

Johan

  • NA
  • 9
  • 1.9k

Insufficient authentication scopes in relation to Syntax “Up

Mar 21 2018 4:59 AM
Goal:
 
Use Google Sheet API by using the syntax code "spreadsheets.values.update" in order to update the current cell.
 
Problem:
 
I have used the code that is provded by Google Sheet's tutorial (https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update) and it doesn't work.
 
I retrieve a error message saying:
 
"An unhandled exception of type 'Google.GoogleApiException' occurred in mscorlib.dll Additional information: Google.Apis.Requests.RequestError Request had insufficient authentication scopes. [403] Errors [ Message[Request had insufficient authentication scopes.] Location[ - ] Reason[forbidden] Domain[global] ]"
 
Info:
*I was enable to use Oath 2.0 authenfication in relation to syntax code "spreadsheets.values.get" (https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get) and it works perfectly.
*The same code of Oath 2.0 that is used in "spreadsheets.values.get" works well.
 
Thank you!
  1. private void btn_test6_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.     UserCredential credential;  
  4.   
  5.     using (var stream =  
  6.         new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))  
  7.     {  
  8.         string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);  
  9.   
  10.         credential = GoogleWebAuthorizationBroker.AuthorizeAsync(  
  11.             GoogleClientSecrets.Load(stream).Secrets,  
  12.             Scopes,  
  13.             "user",  
  14.             CancellationToken.None,  
  15.             new FileDataStore(credPath, true)).Result;  
  16.         Console.WriteLine("Credential file saved to: " + credPath);  
  17.     }
  18.     SheetsService sheetsService = new SheetsService(new BaseClientService.Initializer  
  19.     {  
  20.         HttpClientInitializer = credential,  
  21.         ApplicationName = "Google-SheetsSample/0.1",  
  22.     });  
  23.   
  24.     // The ID of the spreadsheet to update.  
  25.     string spreadsheetId = "";  // TODO: Update placeholder value.  
  26.   
  27.     // The A1 notation of the values to update.  
  28.     string range = "datadata!A1:A6";  // TODO: Update placeholder value.  
  29.   
  30.     // How the input data should be interpreted.  
  31.     SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum valueInputOption = (SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum)0;  // TODO: Update placeholder value.  
  32.   
  33.   
  34.   
  35.     IList<object> my = new List<object>();  
  36.     my.Add("a");  
  37.     my.Add("a");  
  38.     my.Add("a");  
  39.     my.Add("a");  
  40.     my.Add("a");  
  41.     my.Add("a");  
  42.   
  43.     IListobject>> my2 = new Listobject>>();  
  44.     my2.Add(my);
  45.     // TODO: Assign values to desired properties of `requestBody`. All existing  
  46.     // properties will be replaced:  
  47.     Google.Apis.Sheets.v4.Data.ValueRange requestBody = new Google.Apis.Sheets.v4.Data.ValueRange();  
  48.     requestBody.Values = my2;
  49.     SpreadsheetsResource.ValuesResource.UpdateRequest request = sheetsService.Spreadsheets.Values.Update(requestBody, spreadsheetId, range);  
  50.     request.ValueInputOption = valueInputOption;  
  51.   
  52.     // To execute asynchronously in an async method, replace `request.Execute()` as shown:  
  53.     Google.Apis.Sheets.v4.Data.UpdateValuesResponse response = request.Execute();  
  54.     // Data.UpdateValuesResponse response = await request.ExecuteAsync();  
  55.   
  56.     // TODO: Change code below to process the `response` object:  
  57.     Console.WriteLine(JsonConvert.SerializeObject(response));  
  58. }