Google Script ~ How to import Google Sheet data from another users spreadsheet?











up vote
0
down vote

favorite












Apologies in advance for the greenness of this question. But I've been digging through Google's documentation and I can't seem to find an example or explanation for exactly what I'm trying to accomplish. Any help would be greatly appreciated at this point.



~~~ EXPLANATION



I'm writing a stand alone app in Google Script, and I also have a Google Sheet which stores data for that script. The script runs as though executed by the user running it, not as though executed by the owner of the script (myself).



From Google Script main window > Publish > Deploy as web app > Execute app as [user accessing the web app]



In order to access the original spreadsheet which is in my Google Drive, I can't just use Google Scripts



SpreadsheetApp.openById(spreadsheetID);



because person running the app doesn't have the sheet in their Google drive. It's in mine. So I need to use an API call to my Google Sheet, in order to allow the user to access the sheets data. What I have so far is this:



var sheetURL = "https://sheets.googleapis.com/v4/spreadsheets/{sheetID}";
var response = UrlFetchApp.fetch(sheetURL, {muteHttpExceptions: true});


~~~ QUESTIONS



Setting "muteHttpExceptions: false" reveals that I didn't provide an API key. So:



1) How do I get said api key, and can I set the permissions scope of it to read only? given that it's going to be visible to the user.



2) Does this require registering the app with Google, in order to get OAuth set up?



3) Ultimately, what should the api call code end up looking like in the Google Script?










share|improve this question
























  • developers.google.com/sheets/api/guides/authorizing
    – TheMaster
    Nov 20 at 11:20















up vote
0
down vote

favorite












Apologies in advance for the greenness of this question. But I've been digging through Google's documentation and I can't seem to find an example or explanation for exactly what I'm trying to accomplish. Any help would be greatly appreciated at this point.



~~~ EXPLANATION



I'm writing a stand alone app in Google Script, and I also have a Google Sheet which stores data for that script. The script runs as though executed by the user running it, not as though executed by the owner of the script (myself).



From Google Script main window > Publish > Deploy as web app > Execute app as [user accessing the web app]



In order to access the original spreadsheet which is in my Google Drive, I can't just use Google Scripts



SpreadsheetApp.openById(spreadsheetID);



because person running the app doesn't have the sheet in their Google drive. It's in mine. So I need to use an API call to my Google Sheet, in order to allow the user to access the sheets data. What I have so far is this:



var sheetURL = "https://sheets.googleapis.com/v4/spreadsheets/{sheetID}";
var response = UrlFetchApp.fetch(sheetURL, {muteHttpExceptions: true});


~~~ QUESTIONS



Setting "muteHttpExceptions: false" reveals that I didn't provide an API key. So:



1) How do I get said api key, and can I set the permissions scope of it to read only? given that it's going to be visible to the user.



2) Does this require registering the app with Google, in order to get OAuth set up?



3) Ultimately, what should the api call code end up looking like in the Google Script?










share|improve this question
























  • developers.google.com/sheets/api/guides/authorizing
    – TheMaster
    Nov 20 at 11:20













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Apologies in advance for the greenness of this question. But I've been digging through Google's documentation and I can't seem to find an example or explanation for exactly what I'm trying to accomplish. Any help would be greatly appreciated at this point.



~~~ EXPLANATION



I'm writing a stand alone app in Google Script, and I also have a Google Sheet which stores data for that script. The script runs as though executed by the user running it, not as though executed by the owner of the script (myself).



From Google Script main window > Publish > Deploy as web app > Execute app as [user accessing the web app]



In order to access the original spreadsheet which is in my Google Drive, I can't just use Google Scripts



SpreadsheetApp.openById(spreadsheetID);



because person running the app doesn't have the sheet in their Google drive. It's in mine. So I need to use an API call to my Google Sheet, in order to allow the user to access the sheets data. What I have so far is this:



var sheetURL = "https://sheets.googleapis.com/v4/spreadsheets/{sheetID}";
var response = UrlFetchApp.fetch(sheetURL, {muteHttpExceptions: true});


~~~ QUESTIONS



Setting "muteHttpExceptions: false" reveals that I didn't provide an API key. So:



1) How do I get said api key, and can I set the permissions scope of it to read only? given that it's going to be visible to the user.



2) Does this require registering the app with Google, in order to get OAuth set up?



3) Ultimately, what should the api call code end up looking like in the Google Script?










share|improve this question















Apologies in advance for the greenness of this question. But I've been digging through Google's documentation and I can't seem to find an example or explanation for exactly what I'm trying to accomplish. Any help would be greatly appreciated at this point.



~~~ EXPLANATION



I'm writing a stand alone app in Google Script, and I also have a Google Sheet which stores data for that script. The script runs as though executed by the user running it, not as though executed by the owner of the script (myself).



From Google Script main window > Publish > Deploy as web app > Execute app as [user accessing the web app]



In order to access the original spreadsheet which is in my Google Drive, I can't just use Google Scripts



SpreadsheetApp.openById(spreadsheetID);



because person running the app doesn't have the sheet in their Google drive. It's in mine. So I need to use an API call to my Google Sheet, in order to allow the user to access the sheets data. What I have so far is this:



var sheetURL = "https://sheets.googleapis.com/v4/spreadsheets/{sheetID}";
var response = UrlFetchApp.fetch(sheetURL, {muteHttpExceptions: true});


~~~ QUESTIONS



Setting "muteHttpExceptions: false" reveals that I didn't provide an API key. So:



1) How do I get said api key, and can I set the permissions scope of it to read only? given that it's going to be visible to the user.



2) Does this require registering the app with Google, in order to get OAuth set up?



3) Ultimately, what should the api call code end up looking like in the Google Script?







api google-apps-script google-sheets






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 9:10

























asked Nov 20 at 9:04









RobotMonkeyHead

62




62












  • developers.google.com/sheets/api/guides/authorizing
    – TheMaster
    Nov 20 at 11:20


















  • developers.google.com/sheets/api/guides/authorizing
    – TheMaster
    Nov 20 at 11:20
















developers.google.com/sheets/api/guides/authorizing
– TheMaster
Nov 20 at 11:20




developers.google.com/sheets/api/guides/authorizing
– TheMaster
Nov 20 at 11:20

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389504%2fgoogle-script-how-to-import-google-sheet-data-from-another-users-spreadsheet%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389504%2fgoogle-script-how-to-import-google-sheet-data-from-another-users-spreadsheet%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'