Retrieve images in cells using Google Sheets API - google-sheets-api

I'm using the Google Sheets API to return the JSON of a Google Sheet,
e.g
var url = 'https://spreadsheets.google.com/feeds/list/' + id + '/od6/public/values?alt=json';
In one of the cells I have added an image, but this appears empty in the json.
How can I retrieve this image?

This is possible if you use Sheets API v4. If you make a spreadsheets.get request you get access to the =IMAGE(...) formula used in the cell.
GET https://sheets.googleapis.com/v4/spreadsheets/{SPREADSHEET_ID}?
includeGridData=true&ranges={RANGE_A1}&
fields=sheets%2Fdata%2FrowData%2Fvalues%2FuserEnteredValue
200 OK
{
"sheets": [
{
"data": [
{
"rowData": [
{
"values": [
{
"userEnteredValue": {
"formulaValue": "=image(\"https://www.google.com/images/srpr/logo3w.png\")"
}
}
]
}
]
}
]
}
]
}

Related

Google sheets APIv4: Getting notes from cell

I can't find a way to retrieve notes from a cell. I looked here:https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/get
I can update the note by using the code here: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells
... but I can't find a way to retrieve the note in the first place.
This the result of a values.get call on a cell that has a note...
{u'range': u'Sheet1!D5', u'values': [[u'update CD data']], u'majorDimension': u'ROWS'}
as you can see, the notes to the cell are not there.
How about using sheets/data/rowData/values/note to the fields?
The endpoint is as follows.
GET https://sheets.googleapis.com/v4/spreadsheets/### Spreadsheet ID ###?fields=sheets%2Fdata%2FrowData%2Fvalues%2Fnote
From your profile, if you use Python, how about this?
response = service.spreadsheets().get(spreadsheetId=id, fields="sheets/data/rowData/values/note").execute()
Result:
When there are notes at "A1:B2", the result is as follows.
{
"sheets": [
{
"data": [
{
"rowData": [
{
"values": [
{
"note": "sample note A1"
},
{
"note": "sample note B1"
}
]
},
{
"values": [
{
"note": "sample note A2"
},
{
"note": "sample note B2"
}
]
}
]
}
]
}
]
}
Reference:
CellData
If I misunderstand your question, please tell me. I would like to modify it.

MarkLogic - Xpath on JSON document

MarkLogic Version: 9.0-6.2
I am trying to apply Xpath in extract-document-data (using Query Options) on a JSON document shown below. I need to filter out "Channel" property if the underneath property "OptIn" has a value of "True".
{
"Category":
{
"Name": "Severe Weather",
"Channels":[
{
"Channel":
{
"Name":"Email",
"OptIn": "True"
}
},
{
"Channel":
{
"Name":"Text",
"OptIn": "False"
}
}
]
}
}
I tried below code,
'<extract-document-data selected="include">' +
'<extract-path>//*[OptIn="True"]/../..</extract-path>' +
'</extract-document-data>' +
which is only pulling from "Channel" property as shown below.
[
{
"Channel": {
"Name": "Email",
"OptIn": "True"
}
}
]
But my need is to pull from parent "Category" property, but filter out the Channels that have OptIn value as False.
Any pointers?
If I understand correctly, you'd like to extract 'Category', but only with those 'Channel's that have 'OptIn' equalling 'true', right?
Extract-document-data is not advanced enough for that. You best extract entire Categories which have at least one OptIn equalling true (//Category[//OptIn = 'true']), and use a REST transform on the search response to trim down the unwanted Channels..
HTH!

express-graphql: How to remove external "data" object layer.

I am replacing an existing REST endpoint with GraphQL.
In our existing REST endpoint, we return a JSON array.
[{
"id": "ABC"
},
{
"id": "123"
},
{
"id": "xyz"
},
{
"id": "789"
}
]
GraphQL seems to be wrapping the array in two additional object layers. Is there any way to remove the "data" and "Client" layers?
Response data:
{
"data": {
"Client": [
{
"id": "ABC"
},
{
"id": "123"
},
{
"id": "xyz"
},
{
"id": "789"
}
]
}
}
My query:
{
Client(accountId: "5417727750494381532d735a") {
id
}
}
No. That was the whole purpose of GraphQL. To have a single endoint and allow users to fetch different type/granularity of data by specifying the input in a query format as opposed to REST APIs and then map them onto the returned JSON output.
'data' acts as a parent/root level container for different entities that you have queried. Without these keys in the returned JSON data, there won't be any way to segregate the corresponding data. e.g.
Your above query can be modified to include another entity like Owner,
{
Client(accountId: "5417727750494381532d735a") {
id
}
Owner {
id
}
}
In which case, the output will be something like
{
"data": {
"Client": [
...
],
"Owner": [
...
]
}
}
Without the 'Client' and 'Owner' keys in the JSON outout, there is no way to separate the corresponding array values.
In your case, you can get only the array by doing data.Client on the returned output.

Google Vision: Run Multiple Types of Detection on a Single Image

Google Vision Post requests usually look like this:
{
"requests":[
{
"image":{
"content": "image base64 string..."
},
"features":[
{
"type":"LABEL_DETECTION",
"maxResults":1
}
]
}
]
}
As far as I know, this only supports one 'type'.
However, I want Google to analyze for two types: LABEL_DETECTION and FACE_DETECTION.
Is it possible to ask for both in one request?
I'm currently sending two seperate requests, which is kind of inefficient.
try this one, features should be as array
{
"requests":[
{
"image":{
"content": "image base64 string..."
},
"features":[
{
"type":"LABEL_DETECTION",
"maxResults":1
},{
"type":"FACE_DETECTION",
"maxResults":1
}
]
}
]
}

.getjson from external domain. Print from the Array

I'm currently getting 2 arrays from the following get statement.
$.getJSON("http://domain.com?callback=?", function(data){
$("#results").html(JSON.stringify(data));
I'm appending the results in a div with the id results.
All that is doing is just displaying the array. I need to pull certain objects from the array but I can't do that because I am just printing the whole array. How do I get specific information from that array?
Here is some of the data that is being appended to the DIV.
{"me":[{"player":{"high_score":110345,"rank":2}}],"all":[{"player":{"#score := s.score":110345,"avatar":"http://profile.ak.fbcdn.net/hprofile-ak-snc6/195312_789328764_1121893995_q.jpg","guid":"FE4EC535-B74F-4B68-8F4D-2CA0EBC28FAF","name":"Charles Chase","rank":1,"score":110345}},
Thanks!
Provided that the following is your returned JSON data
{
"me": [
{
"player": {
"high_score": 110345,
"rank": 2
}
}
],
"all": [
{
"player": {
"#score := s.score": 110345,
"avatar": "http://profile.ak.fbcdn.net/hprofile-ak-snc6/195312_789328764_1121893995_q.jpg",
"guid": "FE4EC535-B74F-4B68-8F4D-2CA0EBC28FAF",
"name": "Charles Chase",
"rank": 1,
"score": 110345
}
}
]
};
You can use the following to grab the values from the JSON object
CODE
$.getJSON("http://domain.com?callback=?", function(data){
alert(data.me[0].player.high_score);
alert(data.all[0].player.name);
));
Note me and all is returned as array. I hope it helps.