Google Sheets API "(Google::Apis::ClientError)" [duplicate] - ruby-on-rails

I am trying to access Google spreadsheets using a spreadsheet example. When I run the example code it worked fine. I just change the SpreadsheetId and range. It started giving me:
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Unable to parse range: Class Data!A2:A4",
"reason" : "badRequest"
} ],
"message" : "Unable to parse range: Class Data!A2:A4",
"status" : "INVALID_ARGUMENT"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1065)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at poc.mainPOC.main(mainPOC.java:157)
Below is the code:
String spreadsheetId = "my spread sheet ID";
String range = "Class Data!A2:A4";
ValueRange response = service.spreadsheets().values()
.get(spreadsheetId, range)
.execute();

Try replacing Class Data!A2:A4 with A2:A4

If you look at the sheet itself you will notice that the Worksheet is titled "Class Data". So just put the name of your sheet where is says "Class Data". Example:
String range = "SheetName!A1:C";

String range = "Class Data!A2:A4";
The Class Data is your worksheet's name, FYI: the name on the tab at the bottom, the default one is "Sheet1". Replace Class Data with the one you want to work with.

I was trying to add some data to a sheet named Emmett that did not existed yet and was receiving this error:
Error: Unable to parse range: Emmet!A2:C12
I had to manually create the sheet named Emmett in the spreadsheet and then it worked like a charm.

I ran into this error when I had a typo in the name of the tab. In your case "Class Data" didn't match the name of the tab

In my case there was an extra space in the google sheet while I was trimming the sheet name at my end. Once I removed the trimming logic, everything worked fine.

Something that I learned was that If the column name doesn't exist yet, this command won't be able to find it. You need to make sure the column you're writing to already exists -- I did this manually from the google sheet.

Related

Nested IFNA in array Google Sheets

I have the below code. The Course Name, Delivery and Completion Date mismatches work as expected. However I am trying to implement one final row for email mismatch. If the email can't be found in the "another google sheet" I want it to return E-mail mismatch, but it looks as though the iferror is suppressing it. Thoughts/Help?
Thank you in advance.
=ArrayFormula(iferror(if(row(C:C)=1, "Unverified Reason",
IF(ISNA(LOWER(VLOOKUP(C:C,importrange("anothergooglesheet","Course Completion!B:F"),1,0)),"E-Mail Mismatch",
IF(LOWER(VLOOKUP(C:C,importrange("anothergooglesheet","Course Completion!B:F"),4,0))<>LOWER(I:I),"Course Name Mismatch",
IF(LOWER(VLOOKUP(C:C,importrange("anothergooglesheet","Course Completion!B:F"),5,0))<>LOWER(T:T),"Delievery Method MisMatch",
IF(TO_DATE(INT(VLOOKUP(C:C,importrange("anothergooglesheet","Course Completion!B:F"),3,0)))<>F:F,"Completion Date Mismatch",""))))))))
EDIT: I got what I needed by using the following.
=ArrayFormula(iferror(if(row(C:C)=1, "Unverified Reason",
if(A:A="","",
IF(LOWER(VLOOKUP(C:C,importrange("anothergooglesheet","Course Completion!B:F"),4,0))<>LOWER(I:I),"Course Name Mismatch",
IF(LOWER(VLOOKUP(C:C,importrange("anothergooglesheet","Course Completion!B:F"),5,0))<>LOWER(T:T),"Delivery Method MisMatch",
IF(TO_DATE(INT(VLOOKUP(C:C,importrange("anothergooglesheet","Course Completion!B:F"),3,0)))<>F:F,"Completion Date Mismatch",""))))),"Potential E-Mail Mismatch"))
try:
=ARRAYFORMULA({"Unverified Reason";
IF(IFNA(LOWER(VLOOKUP(C2:C, IMPORTRANGE("anothergooglesheet","Course Completion!B:F"),1,)), "E-Mail Mismatch"),
IF(LOWER(VLOOKUP(C2:C,IMPORTRANGE("anothergooglesheet","Course Completion!B:F"),4,))<>LOWER(I:I), "Course Name Mismatch",
IF(LOWER(VLOOKUP(C2:C,IMPORTRANGE("anothergooglesheet","Course Completion!B:F"),5,))<>LOWER(T:T), "Delievery Method MisMatch",
IF(TO_DATE(INT(VLOOKUP(C2:C,importrange("anothergooglesheet","Course Completion!B:F"),3,)))<>F:F, "Completion Date Mismatch",))))})

Azure Data Factory get data for "For Each"component from query

The situation is as follows: I have a table in my database that recieves about 3 million rows each day. We want to archive this table on a regular base, so that only the 8 most recents weeks are in the table. The rest of the data can be archived tot AZure Data lake.
I allready found out how to do this by one day at a time. But now I want to run this pipeline each week for the first seven days in the table. I assume I should do this with the "For Each" component. It should itterate along the seven distinct dates that are present in the dataset I want to backup. This dataset is copied from the source table to an archive table on forehand.
It's not difficult to get the distinct dates with a SQL query, but how to get the result of this query into an array that is used for the "For Each" component?
The issue is solved thanks to a co-worker.
What we have to do is assign a parameter to the dataset of the sink. Does not matter how you name this and you do not have to assign a value to it. But let's assume this parameter is called "date"
After that you can use this parameter in the filename of the sink (also in dataset) with by using "#dataset().Date".
After that you go back to the copyactivity and in the sink you assign a dataset property to #item().DateSelect. (DateSelect is the field name from the array that is passed to the For Each activity)
See also the answer from Bo Xioa as part of the answer
This way it works perfectly. It's just a shame that this is not well documented
You can use lookup activity to fetch the column content, and the output will be like
{
"count": "2",
"value": [
{
"Id": "1",
"TableName" : "Table1"
},
{
"Id": "2",
"TableName" : "Table2"
}
]
}
Then you can pass the value array to the Foreach activity items field by using the pattern of #activity('MyLookupActivity').output.value
ref doc: Use the Lookup activity result in a subsequent activity
I post this as an answer, because the error does not fit into a comment :D
have seen antoher option to accomplish this. That is by executing a pipeline from another pipeline. And in that way I can define the dates that I should iterate over as a parameter in the second pipeline (learn.microsoft.com/en-us/azure/data-factory/…). But unformtunately this leads to the same rsult as when just using the foreach parameter. Because in the filename of my data lake file I have to use: #{item().columname}. I can see in the monitoring view that the right values are passed in the iteration steps, but I keep getting an error:
{
"errorCode": "2200",
"message": "Failure happened on 'Sink' side. ErrorCode=UserErrorFailedFileOperation,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=The request to 'Unknown' failed and the status code is 'BadRequest', request id is ''. {\"error\":{\"code\":\"BadRequest\",\"message\":\"A potentially dangerous Request.Path value was detected from the client (:). Trace: cf3b4c3f-1681-4073-b225-17e1c07ec76d Time: 2018-08-02T05:16:13.2141897-07:00\"}} ,Source=Microsoft.DataTransfer.ClientLibrary,''Type=System.Net.WebException,Message=The remote server returned an error: (400) Bad Request.,Source=System,'",
"failureType": "UserError",
"target": "CopyDancerDatatoADL"
}

How do I set the name a child in Firebase to user input from a text field?

Here's how I want my data tree to look in Firebase:
users:
--Travis:
------travisData:
--Stephanie:
------stephanieData:
My problem is that I can't seem to name a child using user input from a textfield.
Here's the code I have so far:
ref = Database.database().reference()
let username = String(emailTextField.text!)
//ref.child("users").setValue(["username": username])
ref.child("users").setValue(["\(username)": calendar])
The commented out line creates a child named "username" with the textfield.text as its content. But how can I create a child whose name is the textfield.text, with other data as its content? I've tried multiple combinations of using .child and .setValue, but everything keeps throwing me an error when I try to use the username variable instead of a plain string.
Here's the error I get:
Your problem is that Firebase doesn't accept the "." symbol in their user names. You would get the same problem even if you typed a string of letters with a "." such as "adfojnajsdnfjs.fjknasd" instead of "username".
I think you're looking for:
ref.child("users").child(username).setValue(calendar)
Although that depends on the value of calendar.
At the very least this should work:
ref.child("users").child(username).setValue(true)
And give you the following JSON:
"users": {
"Travis": true
}
To write a more complex structure, you can for example do:
ref.child("users").child(username).child("name").setValue(username)
Which results in:
"users": {
"Travis": {
name: "Travis"
}
}
As your require, I think this code will help you
ref.child("users").child("\(inputUsername)").updateChildValues(["travidDataKey": userData])
And
result image
users:
Travid2:
travidDataKey:"Travid Data"

Creating hyperlink from text in Swift

I have a json file which has all the information in text.
One of the node in json looks like this :
"description": "File. Verify File"
What I would like to do is create a hyperlink in a UILabel textfield in swift like :
File ***Verify File***
I tried to do lookup on stackoverflow but nothing was concrete available. I wrote the following code to get the "href" text using Regex.
let regexOptions:NSRegularExpressionOptions?
= NSRegularExpressionOptions.CaseInsensitive
let regex = try NSRegularExpression(pattern: "<a[^>]+href=\"(.*?)\"[^>]*>.*?</a>", options: regexOptions!)
And then use NSMUtableAttributedString to create a link of it. Am I in the correct direction ?
Yes, it's a good approach but you will work more than if your json only have the essential information: { "description": link" } so you can use a UIButton with a #IBAction attached to open a WebController or something like that with the link.

spaces not accepting in ListQuery while querying a list in Google spreadsheet

I am trying to pass a query to a spreadsheet. I have a value say "John cena". How do I pass it in the following line. I am getting an error while doing so
ListQuery query = new ListQuery(listFeedUrl);
query.setSpreadsheetQuery("name = 'John cena' and age > 25");
ListFeed feed = service.query(query, ListFeed.class);
This is the error im getting:
com.google.gdata.util.InvalidEntryException: Bad Request
Parse error: Invalid token encountered
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:594)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
at com.google.gdata.client.Service.getFeed(Service.java:1135)
at com.google.gdata.client.Service.getFeed(Service.java:1077)
at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:662)
at com.google.gdata.client.Service.query(Service.java:1237)
at com.google.gdata.client.Service.query(Service.java:1178)
I'm sorry I don't know the answer completely, but I want to help.
Can you try something like this:
query.setSpreadsheetQuery("name = \"John cena\" and age > 25");
The wiki post # http://code.google.com/apis/spreadsheets/data/3.0/developers_guide.html#SendingStructuredRowQueries says that you have to include data with space in quotations.
I had the same issue, where I had my item column with values that can contain white spaces. By adding double quotes and escaping it in string, I was able to bypass the issue. Also you might want to remove other spaces in the query, apart from the ones between "and", just in case.
String queryString = ""; //should contain feedURL
ListQuery lsListQuery = new ListQuery(new URI(queryString).toURL());
lsListQuery.setSpreadsheetQuery("item=\"Item Name4\" ");
\\This will have the URI encoded
logger.debug(lsListQuery.getQueryUri());
\\This will give you the complete URL
logger.debug(new URI (queryString+lsListQuery.getQueryUri().toString()).toURL());
\\ This should give the feed from which the columns can be read
ListFeed listFeed = service.getFeed(new URI (queryString+lsListQuery.getQueryUri().toString()).toURL(), ListFeed.class);

Resources