admin管理员组

文章数量:1024639

As the title, I got some problem when trying to automate response google forms type collect submitter data but I am not the form's owner Here is the form: Sample Form

Below is my scratch code in GAS:

function submitToGoogleFormWithEmail() {
    var formUrl = ";;
    var email = Session.getActiveUser().getEmail();
    var token = ScriptApp.getOAuthToken();
    Logger.log(token);

    var payload = {
        "entry.1507679348": "lucasdo",
        "entry.21751216": "dnd",
        "entry.528181198": "appscript",
        "emailAddress": email
    };

    var options = {
        'method': 'post',
        "muteHttpExceptions": true,
        'payload': payload,
        'headers': {
            'Authorization': 'Bearer ' + token,
            'Accept': 'application/x-www-form-urlencoded'
        }
    };

    var response = UrlFetchApp.fetch(formUrl, options);
    Logger.log(response.getResponseCode());
}

When I test the code, it showed error code 401 in console log of app script. Console Log Screenshot

I tried with browser console fetching, it worked if I logged in before and go to below url: .1507679348=lucasdo&entry.21751216=dnd&entry.528181198=appscript&[email protected]

Similar thread but not helpful so much: How to auto submitting in require sign-in google form from google apps script

Does anyone have the solution for this case?

As the title, I got some problem when trying to automate response google forms type collect submitter data but I am not the form's owner Here is the form: Sample Form

Below is my scratch code in GAS:

function submitToGoogleFormWithEmail() {
    var formUrl = "https://docs.google/forms/d/e/1FAIpQLSdBdRIYCAaxp2FI4n0rVZywcz0Br7n2DOBOIcWSLHP9B67ikA/formResponse";
    var email = Session.getActiveUser().getEmail();
    var token = ScriptApp.getOAuthToken();
    Logger.log(token);

    var payload = {
        "entry.1507679348": "lucasdo",
        "entry.21751216": "dnd",
        "entry.528181198": "appscript",
        "emailAddress": email
    };

    var options = {
        'method': 'post',
        "muteHttpExceptions": true,
        'payload': payload,
        'headers': {
            'Authorization': 'Bearer ' + token,
            'Accept': 'application/x-www-form-urlencoded'
        }
    };

    var response = UrlFetchApp.fetch(formUrl, options);
    Logger.log(response.getResponseCode());
}

When I test the code, it showed error code 401 in console log of app script. Console Log Screenshot

I tried with browser console fetching, it worked if I logged in before and go to below url: https://docs.google/forms/d/e/1FAIpQLSdBdRIYCAaxp2FI4n0rVZywcz0Br7n2DOBOIcWSLHP9B67ikA/formResponse?entry.1507679348=lucasdo&entry.21751216=dnd&entry.528181198=appscript&[email protected]

Similar thread but not helpful so much: How to auto submitting in require sign-in google form from google apps script

Does anyone have the solution for this case?

Share Improve this question edited Nov 19, 2024 at 3:28 Đỗ Như Đông asked Nov 18, 2024 at 15:54 Đỗ Như ĐôngĐỗ Như Đông 11 bronze badge 12
  • Welcome to StackOverflow! May I ask if you want to get all the emails of the people who responded to the form? – Jats PPG Commented Nov 18, 2024 at 16:34
  • 1 Why are you using an HTTP Post request instead of the Forms Service? – Wicket Commented Nov 18, 2024 at 23:44
  • This might help Post request failed with error code 400 when submitting Google form – Wicket Commented Nov 19, 2024 at 0:15
  • It appears that the Form Settings for "Responses">"Collect email addresses" has been set to Verified. This required two things for the respondent: 1) they are required to login to Google and 2) they are required to physically check the box with the text " Record <<google email address>> as the email to be included with my response. This email address is subsequently catted and passed to a linked spreadsheet BUT when one looks at the "items" in the Form, the "Email address" is not an accessible item. In short, you are trying to update a field that doesn't exist. – Tedinoz Commented Nov 19, 2024 at 2:12
  • @JatsPPG: I am not the form owner, I just want to submit to another user's form. – Đỗ Như Đông Commented Nov 19, 2024 at 2:51
 |  Show 7 more comments

1 Answer 1

Reset to default 0

I can't offer a definitive answer about using Google Apps Script server-side code to post a response to a Google Form owned by someone else that is set to collect the form respondent's email address automatically, but I can mention a couple of things.

Regarding your attempts to use the web browser console and extensions, these options are not directly comparable with using Google Apps Script's FetchUrlApp.fetch, first because this method runs on Google's servers while the mentioned options run on the user's device. Second, the Google Apps Script user cannot control all the possibilities for making HTTP requests due to limitations set by Google, i.e., the user-agent can't be customized. For details, see https://developers.google/apps-script/reference/url-fetch.

In addition to Google Apps Script, other cloud services, such as https://www.postman, can handle HTTP requests. Some of them allow the user to play with more options.

As the title, I got some problem when trying to automate response google forms type collect submitter data but I am not the form's owner Here is the form: Sample Form

Below is my scratch code in GAS:

function submitToGoogleFormWithEmail() {
    var formUrl = ";;
    var email = Session.getActiveUser().getEmail();
    var token = ScriptApp.getOAuthToken();
    Logger.log(token);

    var payload = {
        "entry.1507679348": "lucasdo",
        "entry.21751216": "dnd",
        "entry.528181198": "appscript",
        "emailAddress": email
    };

    var options = {
        'method': 'post',
        "muteHttpExceptions": true,
        'payload': payload,
        'headers': {
            'Authorization': 'Bearer ' + token,
            'Accept': 'application/x-www-form-urlencoded'
        }
    };

    var response = UrlFetchApp.fetch(formUrl, options);
    Logger.log(response.getResponseCode());
}

When I test the code, it showed error code 401 in console log of app script. Console Log Screenshot

I tried with browser console fetching, it worked if I logged in before and go to below url: .1507679348=lucasdo&entry.21751216=dnd&entry.528181198=appscript&[email protected]

Similar thread but not helpful so much: How to auto submitting in require sign-in google form from google apps script

Does anyone have the solution for this case?

As the title, I got some problem when trying to automate response google forms type collect submitter data but I am not the form's owner Here is the form: Sample Form

Below is my scratch code in GAS:

function submitToGoogleFormWithEmail() {
    var formUrl = "https://docs.google/forms/d/e/1FAIpQLSdBdRIYCAaxp2FI4n0rVZywcz0Br7n2DOBOIcWSLHP9B67ikA/formResponse";
    var email = Session.getActiveUser().getEmail();
    var token = ScriptApp.getOAuthToken();
    Logger.log(token);

    var payload = {
        "entry.1507679348": "lucasdo",
        "entry.21751216": "dnd",
        "entry.528181198": "appscript",
        "emailAddress": email
    };

    var options = {
        'method': 'post',
        "muteHttpExceptions": true,
        'payload': payload,
        'headers': {
            'Authorization': 'Bearer ' + token,
            'Accept': 'application/x-www-form-urlencoded'
        }
    };

    var response = UrlFetchApp.fetch(formUrl, options);
    Logger.log(response.getResponseCode());
}

When I test the code, it showed error code 401 in console log of app script. Console Log Screenshot

I tried with browser console fetching, it worked if I logged in before and go to below url: https://docs.google/forms/d/e/1FAIpQLSdBdRIYCAaxp2FI4n0rVZywcz0Br7n2DOBOIcWSLHP9B67ikA/formResponse?entry.1507679348=lucasdo&entry.21751216=dnd&entry.528181198=appscript&[email protected]

Similar thread but not helpful so much: How to auto submitting in require sign-in google form from google apps script

Does anyone have the solution for this case?

Share Improve this question edited Nov 19, 2024 at 3:28 Đỗ Như Đông asked Nov 18, 2024 at 15:54 Đỗ Như ĐôngĐỗ Như Đông 11 bronze badge 12
  • Welcome to StackOverflow! May I ask if you want to get all the emails of the people who responded to the form? – Jats PPG Commented Nov 18, 2024 at 16:34
  • 1 Why are you using an HTTP Post request instead of the Forms Service? – Wicket Commented Nov 18, 2024 at 23:44
  • This might help Post request failed with error code 400 when submitting Google form – Wicket Commented Nov 19, 2024 at 0:15
  • It appears that the Form Settings for "Responses">"Collect email addresses" has been set to Verified. This required two things for the respondent: 1) they are required to login to Google and 2) they are required to physically check the box with the text " Record <<google email address>> as the email to be included with my response. This email address is subsequently catted and passed to a linked spreadsheet BUT when one looks at the "items" in the Form, the "Email address" is not an accessible item. In short, you are trying to update a field that doesn't exist. – Tedinoz Commented Nov 19, 2024 at 2:12
  • @JatsPPG: I am not the form owner, I just want to submit to another user's form. – Đỗ Như Đông Commented Nov 19, 2024 at 2:51
 |  Show 7 more comments

1 Answer 1

Reset to default 0

I can't offer a definitive answer about using Google Apps Script server-side code to post a response to a Google Form owned by someone else that is set to collect the form respondent's email address automatically, but I can mention a couple of things.

Regarding your attempts to use the web browser console and extensions, these options are not directly comparable with using Google Apps Script's FetchUrlApp.fetch, first because this method runs on Google's servers while the mentioned options run on the user's device. Second, the Google Apps Script user cannot control all the possibilities for making HTTP requests due to limitations set by Google, i.e., the user-agent can't be customized. For details, see https://developers.google/apps-script/reference/url-fetch.

In addition to Google Apps Script, other cloud services, such as https://www.postman, can handle HTTP requests. Some of them allow the user to play with more options.

本文标签: How to fetch google form response with required email in Google App ScriptStack Overflow