i've gscript inside a spreadsheet, if i add and run a function calling this code :
var conn = Jdbc.getConnection('jdbc:mysql://sql4.freesqldatabase.com:3306/sql427377', 'sql427377', 'my_pass');
it works !
But if i copy/paste the same code in a google app script :
function doGet() {
return HtmlService.createTemplateFromFile('index').evaluate();
}
function getSql(){
var conn = Jdbc.getConnection('jdbc:mysql://sql4.freesqldatabase.com:3306/sql427377', 'sql427377', 'my_pass');
}
even if i don't call the function, i've just paste the code, i ve got this message on execution of my script :
"Vous devez disposer des autorisations requises pour pouvoir effectuer cette action."
"You must have the required permissions to perform this action."
I don't understand why... need help ;)
Permissions in a script project are asked for every service present in this project. Wether you actually call a function using this service or not is not important.
For example, if I have an onOpen() function in a script and another function that sends emails, I will be asked permission for mailApp service even if I simply try to run onOpen().
If your spreadsheet does not ask anything about Jdbc, it means that the project was already authorized for this service (and you probably forgot it) and the behavior you describe in your other project (the doGet one , but it would be the same in any other project) is normal.
If you want to check this, simply add a call to another Google service in a dummy function and try to execute another function that used to work without warning... You'll get the authorization request as expected.
Related
I'm trying to build an app that does something when it is first installed onto a workspace, eg: Ping every team member.
I couldn't find an event type that gets triggered upon app install:
https://api.slack.com/events
Is there a way to make this happen?
I think there might be a misunderstanding of the events concepts here. Events are always directly linked to one specific Slack app and needs to be processed by that very app. There is no such thing as "general" events for things happening on a workplace, like a new app being installed. Ergo there is no event for app installation.
Nevertheless you can implement the functionality you mentioned with Slack, e.g. pinging all team members once an app is first installed. All you need to do is include this function in the installation process of your Slack app and e.g. start pinging after the installation process is complete and the app verified that it was the first installation to this workspace. You do not need an event for that.
This is a partial answer because I was wondering the same thing and wanted to share what I found. On this oauth tutorial, it has the following code snippet:
app.get('/auth', function(req, res){
if (!req.query.code) { // access denied
return;
}
var data = {form: {
client_id: process.env.SLACK_CLIENT_ID,
client_secret: process.env.SLACK_CLIENT_SECRET,
code: req.query.code
}};
request.post('https://slack.com/api/oauth.access', data, function (error, response, body) {
if (!error && response.statusCode == 200) {
// Get an auth token
let oauthToken = JSON.parse(body).access_token;
// OAuth done- redirect the user to wherever
res.redirect(__dirname + "/public/success.html");
}
})
});
I believe instead of the line res.redirect(__dirname + "/public/success.html"); at that point you can make a request to ping everyone or even call a function to do so directly there, and it will trigger immediately once the app has been installed.
I registered my trigger on Edit->Current Project's Trigger and then made this:
function onEdit(e) {
SpreadsheetApp.getActiveSheet().toast(e.value);
}
I also tried it without registering the trigger in case there's some odd collision thing. Is there something else I need to do to trigger the function?
Either you need to do authorization like tehhowch's comment suggests, or your function has an error. If it has an error and it won't pop up and notify you, try to run the function manually with the debugger and be sure your script is correct.
Here's a bunch of reserved simple trigger functions that you should not use as variable name as they're integral in Apps Script:
onOpen(e) runs when a user opens a spreadsheet, document, or form that he or she has permission to edit.
onEdit(e) runs when a user changes a value in a spreadsheet.
onInstall(e) runs when a user installs an add-on.
doGet(e) runs when a user visits a web app or a program sends an HTTP GET request to a web app.
doPost(e) runs when a program sends an HTTP POST request to a web app.
editing my answer in case I didnt understand what your problem was. I ended up having another issue that was not solved with what I said earlier and I fixed it doing this:
Create a custom menu that runs this:
function addOnEditTrigger(){
var haveTrigger = ScriptApp.getProjectTriggers();
if(haveTrigger.length == 1){ return };
var ss = SpreadsheetApp.getActiveSpreadsheet();
ScriptApp.newTrigger('notifyReportedIssue')
.forSpreadsheet(ss)
.onEdit()
.create();
}
A new user can copy that file, open it, open the menu, run the function and create the needed trigger right there.
OLD answer:
Dont use onEdit(e)
Create another function: myFunctionToRunOnEdit(e) and then set a trigger that runs the function onEdit
image of trigger
I got questions about Android 6 (Marshmallow) runtime permission. If user wants to pick a photo from gallery, should we ask for READ_EXTERNAL_STORAGE permission?
Seems like I could access the gallery even though I turn off the Storage permission.
You need to ask for READ_EXTERNAL_STORAGE. You will be able to access the gallery without it, but if you want to do anything with the media you get from the gallery you will need the READ permission.
A quick test on what happens in onActivityResult after an image has been picked form the gallery:
Permission Denial: reading com.android.providers.media.MediaProvider
uri content://media/external/images/media from pid=8405, uid=10177
requires android.permission.READ_EXTERNAL_STORAGE, or
grantUriPermission()
For custom permission,you may use runtime permission if you are using Android 6.0 or above.This code may help you .
If your app doesn't already have the permission it needs, the app must
call one of the requestPermissions() methods to request the
appropriate permissions. Your app passes the permissions it wants, and
also an integer request code that you specify to identify this
permission request. This method functions asynchronously: it returns
right away, and after the user responds to the dialog box, the system
calls the app's callback method with the results, passing the same
request code that the app passed to requestPermissions().
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.READ_CONTACTS)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.READ_CONTACTS},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
To Know more about runtime permission
https://developer.android.com/training/permissions/requesting.html
I having an issue with FB.ui permissions.request window.
FB.ui({
method: 'permissions.request',
perms: 'publish_actions',
display: 'popup'
},function(response) {
// This function is never called ? });
Context :
I use the new OAuth window (with timeline), i have configured my apps to work with it.
I'm french and use Facebook in French.
First issue :
- My callback function is never called ...
Second issue :
- The new OAuth window, seem to be not the good window.
It's called 'permission request' but inside it is the copy of login window. And no permission request is displayed.
So, my question is : how can i do the permission request in js ?
How displaying this window : https://developers.facebook.com/attachment/app_extended_perms.png/ ?
Thanks.
The reason you are not seeing it is because the application process has become a two step process.
Being that the person accepts to login into your application.
Being the person accept your extended permission which is where the callback url comes into play.
Documentation can be found here.
So the reason your callback isn't being called is because the two step process. I would suggest making the response attached to second page that is called.
I am not sure how the JS SDK works but it is how I managed to do it.
Goodluck.
Disable "Enhanced Auth Dialog" in your app's advance settings and see if it works. If you want to stick with Enhanced Auth Dialog then checkout Setup Auth Dialog Preview for Authenticating user section of this tutorial.
I'm looking for a way through AJAX (not via a JS framework!) to real time monitor a file for changes. If changes where made to that file, I need it to give an alert message. I'm a total AJAX noob, so please be gentle. ;-)
Edit: let me explain the purpose a bit more in detail. I'm using a chat script I've written in PHP for a webhop, and what I want is from an admin module monitor the chat requests. The chats are stored in text files, and if someone starts a chat session a new file is created. If that's the case, in the admin module I want to see that in real time.
Makes sense?
To monitor a file for changes with AJAX you could do something like this.
var previous = "";
setInterval(function() {
var ajax = new XMLHttpRequest();
ajax.onreadystatechange = function() {
if (ajax.readyState == 4) {
if (ajax.responseText != previous) {
alert("file changed!");
previous = ajax.responseText;
}
}
};
ajax.open("POST", "foo.txt", true); //Use POST to avoid caching
ajax.send();
}, 1000);
I just tested it, and it works pretty well, but I still maintain that AJAX is not the way to go here. Comparing file contents will be slow for big files. Also, you mentionned no framework, but you should use one for AJAX, just to handle the cross-browser inconsistencies.
AJAX is just a javascript, so from its definition you do not have any tool to get access to file unless other service calls an js/AJAX to notify about the change.
I've done that from scratch recently.
I don't know how much of a noob you are with PHP (it's the only server script language I know), but I'll try to be as brief as possible, feel free to ask any doubt.
I'm using long polling, which consists in this (
Create a PHP script that checks the content of the file periodically and only responds when it sees any change (it could include a description of the change in the response)
Create your XHR object
Include your notification code as a callback function (it can use the description)
Make the request
The PHP script will start checking the file, but won't reply until there is a change
When it responds, the callback will be called and your notification code will launch
If you don't care about the content of the file, only that it has been changed, you can check the last-modified time instead of the content in the PHP script.
EDIT: from some comment I see there's something to monitor file changes called FAM, that seems to be the way to go for the PHP script