Jump to content

Google Client API Module


dragan
 Share

Recommended Posts

For the first time ever, I tried to play around with PW's new Google Client API module. Installation was successful.

The basic example with Sheets API (reading content from a sheet) went well.

However, writing to a sheet throws an error:

// Google_Service_Exception #400

{
  "error": {
    "code": 400,
    "message": "Requested writing within range [Tabellenblatt1!A1:A2], but tried writing to column [B]",
    "errors": [
      {
        "message": "Requested writing within range [Tabellenblatt1!A1:A2], but tried writing to column [B]",
        "domain": "global",
        "reason": "badRequest"
      }
    ],
    "status": "INVALID_ARGUMENT"
  }
}

I have used Ryan's example. The sheet gets created, but nothing else happens.

Does anyone know what this error message means in plain English?

Link to comment
Share on other sites

Ciao @dragan, unfortunately I cannot test it right now . The message suggests an issue with the spreadsheet columns or in the way columns are addressed. 

What is curious is the spreadsheet tables range (Tabellenblatt1!A1:A2) as Ryan's example does not directly defines a range. Going inside GoogleSheets.php, the function setRows() is defining the range:

public function setRows($fromRowNum, array $rows, array $options = array()) {
  $fromRowNum = (int) $fromRowNum;
  $numRows = count($rows);
  if(!$numRows) return false;
  $toRowNum = $fromRowNum + ($numRows - 1);
  $range = $this->rangeStr("A$fromRowNum:A$toRowNum");
  return $this->setCells($range, $rows, $options); 
}

Franky I do not understand why the function is fixing the range within column "A" only (A1:A2). It sounds to me strange also the second column of the range is hardwired to "A" ... but probably is due to the fact each row is managed like an array of columns starting with column "A" ... ?... need to study the code deeper.

By the way, googling around I found the following links

https://stackoverflow.com/questions/46350876/error-trying-to-write-a-row-in-google-sheets-using-api-v4 this case the same error (very similar) is reported and the issue seems to come from spreadsheet addressing notation

 https://help.formstack.com/hc/en-us/articles/360019521651-Google-Sheets-Commonly-Returned-Errors this one is a bit more generic and not sure it is the case.

I hope you may find some hints with them.

 

Link to comment
Share on other sites

@Edison Thanks for your feedback. I have googled far and long, and have also looked in the module code.

I can append to existing sheets easily, and reading from them too.

I don't know why Ryan didn't implement $range as a parameter, but only $fromRowNum (int). Probably because in most cases, that's all you need.

Could just as well be an oddity with the original Google API code... *shrugh*

Link to comment
Share on other sites

1 hour ago, Edison said:

Franky I do not understand why the function is fixing the range within column "A" only (A1:A2). It sounds to me strange also the second column of the range is hardwired to "A" ... but probably is due to the fact each row is managed like an array of columns starting with column "A"

To me it looks like it should definitely be Spreadsheetname!1:2 since the API complains that it doesn't like writing outside of the given range. It likely behaves differently depending on whether overwrite is true or false, so it might not have popped up in practice (FormBuilder entries will be passed through appendRows). I'm going to run a few tests.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...