Using Google Sites, How can I connect to another user spreadsheet using username and password, alike one usually does with mysql?
I tried the following, but it did not work :
var opts = {dataType:'json',username:'xxxxx',password:'xxxxxx'};
var query = new google.visualization.Query(urlTable, opts);
yes i need to connect to a spreadsheet, who owner is other user(spreadsheet is in other account), from code JS with top two lines that i posted at the first post in this thread
using username and password that i have
i see this https://developers.google.com/gadgets/docs/oauth#examples but i dont understand well
thanks
The error in site is Access denied because the owner of document is other gmail account...
Related
I'm writing a signoff script in Google Apps Script for GSheets that allows users to select their name from a dropdown list in a cell, then if the name matches the currently active account, another function will run to lock the row etc. Everything is working perfectly on my gmail account, but when the client tries to run the script using an account managed by google but with a non-gmail domain, the email address check fails. I'm waiting on the client to send me the log info as I don't have permissions to access it in their file, but wanted to see if anyone else had run into this issue.
In the example code with modified company and username, the code does NOT work, but if I set atDomainString to "#gmail.com" and name to my gmail address and run under my account, it does.
const atDomainString = "#redactedcompany.com";
const name = "JSmith";
function userMatchesSignature(name) {
let user = Session.getEffectiveUser().toString().toLowerCase();
let signUser = (name + atDomainString).toLowerCase();
Logger.log("User: <"+user + "> vs <" + signUser +">");
return user === signUser;
}
Try to grab their error message to confirm what's going on. But most likely they're blocking access to the client ID. Since the scripts that try to access user data might be blocked.
Depending on the scopes you're using on your project, they might need to verify the app https://support.google.com/cloud/answer/7454865
Best practice
Create the project using a domain account instead of a free Gmail account. Because they might run into scopes issues. In their domain, they can mark the app as internal.
Request:
I need to Connect a Service using JS with a Private Google Sheet. It's not needed to get the end user to sign in into a Google Account, I only need to show some data from that Private Google Sheet into the Web page.
I already have a Key and a Client ID which I use following these steps https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get
It works so far, the issue that I have with my request is that this sample get the end user to sign in into a Google account to then make the Api Call.
NOTE: if the Google Sheet is Shareable by a link then I can connect with the Key, however the Google Sheet should be private to only grant access to some people.
Is there a way to only consume the data from the Private Google Sheet without to get the end user sign in into the Google Account?
As suggested in the comments, you can use a Web App as an API to make a get or post request from your JavaScript application, in order to not need credentials/token for those requests you need to deploy the web app with the option "who has acces to the app" set to "anyone, even anonymous" and the option "Execute as" set to "me" so it can be run under your credentials. An example of a simple web app to which you can do a get request to the deployed url is below:
function doGet() {
var spreadsheet = SpreadsheetApp.openById("[SPREADSHEET-ID]");
var sheet = spreadsheet.getSheetByName("Sheet1");
var values = sheet.getRange("A2:E6").getValues();
var stringOutput = values.toString();
return ContentService.createTextOutput(stringOutput);
}
This will retrieve the values from the "A2:E6" range as a string.
I am setting up a spreadsheet whose users do not necessarily have a Google account nor should be required to log in.
I would like to interact with users in two ways that are possible with the Browser class. One is displaying an alert in a pop-up window, in order to warn users not to edit a field. This is done with Browser.msgBox or ̀€ui.alert. The second thing is requesting an input in a window, which is done nicely with Browser.inputBox().
While my code works fine when I am logged in as owner, it is useless when edited by an unregistered user.
Can I make those function work for unregistered users and if so, how?
Otherwise, are there workarounds to achieve similar functionalities?
Here is a minimal example of what I did:
function onEdit(event) {
var ss = SpreadsheetApp.getActiveSheet();
var eventRange = event.range;
var eventRow = eventRange.getRow();
var eventCol = eventRange.getColumn();
if(eventCol == 1){
protectDateField(ss, eventRow, eventCol)
}
}
function protectDateField(ss, eventRow, eventCol){
var ui = SpreadsheetApp.getUi();
ui.alert("Do Not Edit This Field!");
ss.getRange(eventRow,eventCol).clearContent();
}
Short answer
What you want to do it's not possible on Google Sheets.
Explanation
To run a script bounded to a spreadsheet the user should be an editor for that spreadsheet.
Simple triggers can't access services that require authorization to run.
Some additional restrictions apply when triggers are triggered by anonymous users.
NOTES:
The required authorization scopes by each method are included on the documentation section for each method.
Anonymous users can't authorize scripts to be ran by installable triggers as the authorization process requires a usar account to log the respective authorization.
For further details see:
https://developers.google.com/apps-script/guides/sheets
https://developers.google.com/apps-script/guides/triggers
Workarounds
There is no way to achieve the desired functionality by solely using Google Sheets, but you could
create a web app by using Apps Script and embed on it a spreadsheet
create a web app by using another platform and embed on it spreadsheet
See below for part of html code my featureLayer is saved in my arcgisonline;
var search = new Search({
sources: [{
featureLayer: new FeatureLayer("https://services1.arcgis.com/BZNs0xaSHDSi4V6G/arcgis/rest/services/postcodes/FeatureServer/0",
When I run the code, it ask to enter arcgisonline username and password.
when I do this, it says incorrect username and password.
This is the same username and password, I would have used to login in directly in my ArcGIS account.
Any hint or suggestion is appreciated!
Well, You might be typing incorrectly.
Because this is the only way to access secured(Non shared) layer. you HAVE to enter the AGOL credentials while accessing the secured(non shared) layer in your application.
There is alternative way to avoid the identity manager or Credentials simply share you AGOL GIS feature layer with everyone.
As you can see in below screenshot. (these are the layers published by you)
I am not able to see "postcodes" layers in it.
This can also be a reason that either you haven't publish the layer properly or it's not shared with anyone.
Hoping this will help you :)
I have a form on a website that needs to check my calendar to see what times are available, and then later when it's submitted it's going to send an email.
I created a service account in the API console but I have no idea how to grant it access to my account.
Here's what I have so far, trying to list labels of my Gmail account as a test.
var google = require( 'googleapis' );
var gmail = google.gmail('v1');
var key = require('../client_secret.json');
var authClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
['https://mail.google.com/'],
'****#gmail.com');
authClient.authorize(function (err, tokens) {
if (err) {
return console.log(err);
}
gmail.users.labels.list({
auth: authClient,
userId: '****#gmail.com'
}, function (err, resp) {
if (err) {
return console.log(err);
}
console.log(resp);
});
});
And when I run the script I get:
[Error: unauthorized_client]
Edit:
I've also tried another auth flow using oauth, where it takes you to the typical permission screen asking you to Allow access for "project name" to "whatever scopes you put". Then I can use the access token to make requests and everything is good... but this doesn't feel right because I don't ever want any other user to authorize. I could use a route to authorize the "app" 1 time and then disable that page so it can't be accessed again... It feels kind of hack-y.
I have partially solved my problem; at least, I have gotten the example in my question to work.
In the Developer Console I had to edit my service account and check a box to enable "Domain-wide delegation".
You go to your Service Accounts, click the little 3 dot menu icon to the right of your service account, click edit and in the popup dialog there is a checkbox that you need to check.
I had previously seen something about Domain-wide Delegation but in that example they were saying to go to your Google Apps account, which I don't have, so I thought it didn't pertain to me, but after tinkering around in the Developer Console I found that checkbox and the Gmail example above works, as well as other parts of the Gmail API including reading messages from my inbox.
However, I tried doing a request to the Calendar API and I am getting an error, but I think that calls for a different question.