How to access cell values from a Google Sheet? - javascript

I have the greatest trouble finding information about what I need. I guess I'm not looking in the right places since this is quite basic. Anyway.
Somebody somewhere has created a Google Sheet anyone with the link can access. I want to retrieve the value of a given cell.
I'd like to be able to do the following in JS from a simple web page (or server side in PHP, but preferably JS):
AGoogleApiIHopeExists.setApiKey("<MY_API_KEY");
var value = AGoogleApiIHopeExists
.getSheet("AJEIDNNS6886SDHSKN67HBS7BA6SD555DSHD")
.getTab("MyTabInsideMySheet")
.getCell("B:17");
I'm afraid I'm a bit naive to think this is possible...
If not, where should I look for more info?

Try reading through the Google Sheets API. It is a REST API you can use to access & edit Google sheets. You do not need their client libraries (Java, .NET, etc.)
If the sheet is private, you will need to use OAuth 2.0 to gain access through a user account.
If the sheet is public, you will be able to access it without login. Note though that the sheet must still be published before you can access it.
I did some digging to help you out. Try this endpoint:
https://spreadsheets.google.com/feeds/cells/<sheetID>/default/public/full/R1C1?alt=json
R1C1 refers to Row 1, Column 1. You can change this as needed. default refers to the worksheet (tab) ID. If you need a different worksheet than the default, there are other API endpoints you can use to fetch the appropriate worksheet ID.
Here is a simple jsfiddle which allows you to enter a few variables and see the resulting value.

Related

Send message to Slack channel when Google Sheet column gets updated (Google Script)

I'm trying to connect my Google Sheet with a Slack Channel. The use case is as follow:
I have a Google Sheet which looks like this:
There are around 50 so called topics, each of them has internal and external experts listed, also some related files. For now, only the internal experts column of each topic is of interest. Whenever a new person is listed as an internal expert (new cell on the bottom of the column), I want to send out a message to a related slack channel which looks like this:
The message should contain the name or content of the added cell and the name of the Topic he/she was added in as an internal expert (in this case "Topic 1"). The rest is a predefined string. As you can see, I tried to do this with Zapier, and it works. The problem is with Zapier, there seem to be too many limitations when working with several columns. As far as I know, I would have to create a separate Zapier Action for each column, which isn't a really nice solution.
Does anybody can give me a hint how to build this with a Google Script (+ Slack Webhook)? Or if it even makes sense to do so? I'm not an expert in JavaScript + datasets, so I'm struggling a bit on how to start this.
I would suggest to take a look at Triggers for Google App Scripts. You can set a trigger to run every time your Google sheet is edited - see onEdit(). Your trigger can than check if the edit is relevant (e.g. new cell at the bottom of a specific column) and send a request to Slack using incoming webhooks.

I need to make a PUT request to a JSON file in an external API. I need to update specific fields

I have a JSON on an external API, and, in the documentation of the API, it instructs to use a PUT request to update records. I have read a lot on this, but I haven't found an adequate amount of information.
I will do my best to provide you with the most info I can so you can help me, specifically.
I have the url stored in a variable: $record.
The documentation instructs to: Set the request body content as a json formatted array of record data. This is the “payload”.
It also provides an example:
{
“Name”: “Craig J. Peters”,
“Job Title”: “Director of Engineering”
}
I need to change specific fields. How can I accomplish this using cURL and PHP?
I should mention: If this is easier with JavaScript, I am open to that as well.
I strongly recommend you to check Guzzle as a starting point -
http://docs.guzzlephp.org/en/latest/request-options.html#body

Tealium tagging for errors while loading of the page

I am just very new to Tealium tagging and I want to use the tags whenever an error comes at the loading of a page.
I am using subscribe-publish for showing the error on screen. Now I want to send the error information for analytics purpose everytime an error comes.
Want to send info like error type, page name, site name etc.
Can you please help how to have this implemented using tealium? Please start the explanation from the very basics as I am literally just a beginner :P
Thanks in advance.
First, the asynchronous Tealium script would need to be included on the page.
Create the UDOs for each of the elements you're planning to capture information about (e.g. "error_type", "page_name", "site_name", etc) and consider adding some friendly aliases. These will be the values you need to populate the data layer with when such an error occurs. At this point, assuming you're using the default data layer name of "utag_data", your page will need to have the following JavaScript in the data layer object on the page before the Tealium script is referenced:
utag_data = {
"page_name": "my webpage",
"error_type": "bad request",
"site_name": "my website"
}
Add a tag for the analytics solution you wish to use and set up the appropriate dimensions/variables you wish to store the information within. This usually involves opening the mapping control within the tag, picking the variable you wish to store the information in and mapping it to your UDO that you created previously. Ensure that any analytics-side mapping is done as well since you may need to explicitly define what sort of information you're sending in.
At this point, you just need to save and publish to the environment you're planning to capture the data within (though testing in a staging environment is a good idea too). When you visit the page and there's an error, assuming you did the above, you should see the network request in your browser's developer tools going to the analytics system with the data you provided.

How to automatically save the headline for every new article provided my 3rd party js script is embed on a website

I am working on a something similar to Disqus, and I created a third-party javascript snippet which the user will embed in the website and have a rating widget for each article. Users can rate the article using the widget. Everything is working, the server is making the request, but I am making the article object instance explicitly.
I need to automate this, like for a new article on the website, checking the request is coming from the authenticated website and create a new rating widget in the Database in Django and Django-rest-framework.
I am using Python 2.7.
Question:
How do I automatically save the headline of the new article, if its new and authenticated in the database?
I know that I need to use a model to implement this, but I am unsure how to do the actual implementation.
EDIT:
Let's say this is the query
https://example.com/embed/comments/?base=default&version=edb619270a92c3035c453faa7c9444d1&f=example&t_i=article_2431522&t_u=http%3A%2F%2Fwww.firstpost.com%2Fbollywood%2Flatest-trailer-of-spectre-is-out-james-bond-is-back-all-guns-and-cars-blazing-2431522.html%09&t_e=Latest%20trailer%20of%20%27Spectre%27%20is%20out%3A%20James%20Bond%20is%20back%20all%20guns%20and%20cars%20blazing&t_d=Latest%20trailer%20of%20%27Spectre%27%20is%20out%3A%20James%20Bond%20is%20back%20all%20guns%20and%20cars%20blazing&t_t=Latest%20trailer%20of%20%27Spectre%27%20is%20out%3A%20James%20Bond%20is%20back%20all%20guns%20and%20cars%20blazing&s_o=default
In my model I need save the following, like f to forum (where forum=models.CharField("short name", max_length=30, unique=True)
I know I need to parse the url for every &, but don't know how. I checked the documentation of rest-framework, but I didn't get the gist of it.
`f ---->forum,
t_i----> identifier,
t_u----> url
t_s----> slug,
t_e----> title,
t_d----> documentTitle,
t_t----> title || documentTitle,
t_c ---->category,
s_o----> sortOrder,
l----> language`
What's the best practice to save?
Hope this helps
I'm going to just answer the question you stated at the end: "How do I automatically save the headline of the new article"
You're right, you'll need to create an Article model that mirrors the 3rd party site's articles.
It'll need to have a field for the title/headline (probably CharField), make sure you make it big enough and/or deal with cases where the title is bigger.
You'll also need a unique ID for each article. Ideally, rather than using Django's default, you'll use whatever the 3rd party site is using as the unique ID as a One to One mapping.
Then whenever a request comes in you can use the get_or_create method to ensure the article exists in your DB.

Using Google Spreadsheet as JSON file using tabletop to datatables returns error

I'm a relative newbie when it comes to coding, especially javascript. I currently am trying to populate a table from a google spreadsheet, which will update when the spreadsheet is.
I followed this tutorial word for word (basically all you need to do is replace the key with your own to specify your spreadsheet, and make sure its both published and public, which I've done)
http://dataforradicals.com/the-absurdly-illustrated-guide-to-sortable-searchable-online-data-tables/
I just get a bad request 400 error referring to my spreadsheet. If I visit the spreadsheet generated directly I just get the words...
"Invalid query parameter value for sq."
https://spreadsheets.google.com/feeds/list/1UcfO9GHePQrcixZB_R9uVXr1vHVqVTDg7DdsOjpm-K0/od6/public/values?alt=json-in-script&sq=&callback=Tabletop.callbacks.tt140241226993949106
I can visit my spreadsheet with the link I was given when I published it here..
[maximum links reached but the structure is different]
As you can see the domain structure is different. I fear that "Tabletop to Datatables" is adding an outdated url to the start of that link but can't find where it actually applies it.
The only reason I would think thats not happening is because the example in the tutorial still works! And the link it refers to is the old style URL too
I'm baffled, please help if you can. All suggestions appreciated
The query string includes a parameter without a value, &sq=.
https://spreadsheets.google.com/feeds/list/1UcfO9GHePQrcixZB_R9uVXr1vHVqVTDg7DdsOjpm-K0/od6/public/values?alt=json-in-script&sq=&callback=Tabletop.callbacks.tt140241226993949106
^^^^
Try this, with that parameter completely removed...
https://spreadsheets.google.com/feeds/list/1UcfO9GHePQrcixZB_R9uVXr1vHVqVTDg7DdsOjpm-K0/od6/public/values?alt=json-in-script&callback=Tabletop.callbacks.tt140241226993949106
There is an updated version of this project. Any necessary updates are included here:
https://github.com/scottpham/tabletop-to-datatables
Try with the updated versions of all js libraries.
Check the link and remove the extra string after pub. That part of link is not necessary and may cause issues.
According to google:
The 400 Bad Request error is an HTTP status code that means that the request you sent to the website server, often something simple like a request to load a web page, was somehow incorrect or corrupted and the server couldn't understand it.
Good luck

Categories

Resources