Google-api-dotnet-client: Google.Apis.Requests.RequestError 'valueInputOption' is required but not specified [400]

Created on 27 Sep 2018  路  5Comments  路  Source: googleapis/google-api-dotnet-client

i still have this message even i try to change scope Google.Apis.Requests.RequestError
'valueInputOption' is required but not specified [400] can some one help please !

question

Most helpful comment

Right, so this is the problem:

SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum valueInputOption =
    (SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum)0;  // TODO: Update placeholder value.

The value 0 isn't value for ValueInputOption. See https://developers.google.com/sheets/api/reference/rest/v4/ValueInputOption

I'm going to close this issue as it looks like it's not an issue with the .NET libraries.

All 5 comments

Could you give us a bit more information about what API you're trying to call, and what this has to do with scopes? It sounds like you should be specifying a ValueInputOption property somewhere, but without knowing anything about what you're trying to achieve, it's very hard to help.

I'm using a google api, and this is my full code:

using Google.Apis.Auth.OAuth2;
using Google.Apis.Sheets.v4;
using Google.Apis.Sheets.v4.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using Newtonsoft.Json;
using System.IO;
using System.Threading;
using Data = Google.Apis.Sheets.v4.Data;

 private void button3_Click(object sender, EventArgs e)
        {
            string[] Scopes = { SheetsService.Scope.Spreadsheets };
            string ApplicationName = "Google Sheets API .NET Quickstart"; //SheetUpdate update this!

            UserCredential credential;

            using (var stream =
                new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }


            SheetsService sheetsService = new SheetsService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential,
                ApplicationName = ApplicationName,
            });

            // The ID of the spreadsheet to update.
            string spreadsheetId = "spreadsheetid";  // TODO: Update placeholder value.

            // The A1 notation of the values to update.
            string range = "Feuille 3!A1:A6";  // TODO: Update placeholder value.

            // How the input data should be interpreted.
            SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum valueInputOption = (SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum)0;  // TODO: Update placeholder value.



            IList<object> my = new List<object>();
            my.Add("a");
            my.Add("a");
            my.Add("a");
            my.Add("a");
            my.Add("a");
            my.Add("a");

            IList<IList<object>> my2 = new List<IList<object>>();
            my2.Add(my);



            // TODO: Assign values to desired properties of `requestBody`. All existing
            // properties will be replaced:
            Google.Apis.Sheets.v4.Data.ValueRange requestBody = new Google.Apis.Sheets.v4.Data.ValueRange();
            requestBody.Values = my2;






            SpreadsheetsResource.ValuesResource.UpdateRequest request = sheetsService.Spreadsheets.Values.Update(requestBody, spreadsheetId, range);
            https://docs.google.com/spreadsheets/d/spreadsheetid/edit#gid=495609347

            request.ValueInputOption = valueInputOption;

            // To execute asynchronously in an async method, replace `request.Execute()` as shown:
          // Data.UpdateValuesResponse response = request.Execute();
            Google.Apis.Sheets.v4.Data.UpdateValuesResponse response = request.Execute();

            // Data.UpdateValuesResponse response = await request.ExecuteAsync();

            // TODO: Change code below to process the `response` object:
            MessageBox.Show(JsonConvert.SerializeObject(response));
        }

when i debug my app i get this error :

Google.GoogleApiException聽: 'Google.Apis.Requests.RequestError
'valueInputOption' is required but not specified [400]
Errors [
Message['valueInputOption' is required but not specified] Location[ - ] Reason[badRequest] Domain[global]
]

Right, so this is the problem:

SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum valueInputOption =
    (SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum)0;  // TODO: Update placeholder value.

The value 0 isn't value for ValueInputOption. See https://developers.google.com/sheets/api/reference/rest/v4/ValueInputOption

I'm going to close this issue as it looks like it's not an issue with the .NET libraries.

please can you spicific what i should i do in this ValueInputOption , if you can give me an example

Set it to one of the values in the enum - read the documentation I linked to before to work out which you want.

Was this page helpful?
0 / 5 - 0 ratings