ONLAEG
ONLAEG

Reputation: 199

How to pass You need permission when access webapp be create by google app script

I have two Google Apps Scripts like this:


Script A:

This is a webapp. I use it like a web api. Depend on parameter I will return data what I read from a SpreadSheet only I can access and I will add or edit data in this SpreadSheet.

I published it with following options:

Execute as me

Who has access to the web app:Anyone


Script B:(in a SpreadSheet)

I use this SpreadSheet like a input form. And I will request to script A by UrlFetchApp function.


The problem: When I use UrlFetchApp function, the response content is a html like following image. I think this is a request access dialog what will send a request mail to script A owner. I tried to share script B project to test user. It work fine. But I want to show html dialog and do something for test user can send mail normally.


Questions:

How can I show this html content on a dialog in SpreadSheet B?

If have another way which I must not share script A project to other one, tell me please! Because they can see my script A when I shared it to them.

You need permission

I have used ScriptApp.getOAuthToken to verified webapp like this:

function requestAPI(request_parameter_string) {
    var param = {
        method      : "get",
        headers     : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
        followRedirects : true,
        muteHttpExceptions:true
    };
    
    Logger.log("run to this");
    var url = "https://script.google.com/macros/s/" + api_id + "/exec?" + request_parameter_string;
    var response = UrlFetchApp.fetch(url,param);
    if(response.getContentText() != "Success"){
        return response.getContentText();
    }
}

Upvotes: 1

Views: 2519

Answers (1)

Tanaike
Tanaike

Reputation: 201378

Your situation is as follows.

  • Web Apps is deployed as Execute as me snd Who has access to the web app:Anyone.
  • You want to make users access to your Web Apps using the access token.

If my understanding is correct, how about this modification?

Modification points:

  • If you access to Web Apps that you are owner, you can access using the access token.
  • If other users access to your Web Apps, when the project file which deployed Web Apps is shared to users, users can access using the access token.
    • When the file is not shared, such error occurs.
    • If you use the container-bound script, please share it.
    • If you use the standalone script, please share it.
  • For the access token, https://www.googleapis.com/auth/drive is required to be included in the scopes.

References:

Upvotes: 2

Related Questions