1
votes

So here is the "Example" for apps script External APIs.

https://developers.google.com/apps-script/external_apis

But when you cut-and-paste the code:

var url = "https://gdata.youtube.com/feeds/api/videos?"
    + "q=skateboarding+dog"
    + "&start-index=21"
    + "&max-results=10"
    + "&v=2";
var response = UrlFetchApp.fetch(url);

into a Code.gs

function myFunction() {

 var url = "https://gdata.youtube.com/feeds/api/videos?"
    + "q=skateboarding+dog"
    + "&start-index=21"
    + "&max-results=10"
    + "&v=2";
var response = UrlFetchApp.fetch(url);

}

and press the "publish Deploy as Web app" (after managing the project) Nothing happens.

Is there a working example not just the above snippet? In other words what do you do with the response var to "Display" the query to YouTube etc? This URL-fetch example is said to be needed to understand numerous tutorial examples but doesn't itself actually accomplish anything.

Thanks

I responding here to the response to the answers below.

I tried Browser.msgBox(response); and that gives me "unknown macro doGet.”

I tried Logger.log(response); and that gives me “unknown macro doGet.”

function myFunction() {
    var url = "https://gdata.youtube.com/feeds/api/videos?"
    + "q=skateboarding+dog"
    + "&start-index=21"
    + "&max-results=10"
    + "&v=2";
var response = UrlFetchApp.fetch(url);

//Browser.msgBox(response);

// Logger.log(response);

}

You say "that's up to you as a developer" But I don't know what it is supposed to do “as a developer”

Yes it's obvious i am missing something here, that is the problem. I am missing something fundamental that is assumed I should know from the example but I do not know it.

I was not introduced to Listbox in the tutorials.

When I type “listbox” into the search at /apps-script I get this example:

https://developers.google.com/apps-script/class_listbox

I put this into a spreadsheet and am able to Run it to get the selection choices. So why is this different from what I should get with msgbox, or logger? These both get me ‘Unknown macro doGet”

Please I am lost here. I need to undertand this before proceeding with the other tutorials but am missing something.

OK I've found a way to get the "response" to show but not using the "Deploy as a web app" (which is what I think I need, but I guess i don't know.

function onOpen() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();

// These are the 2 menu entries var menuEntries = [ {name: "Surprise 1", functionName: "menuItem1"}, {name: "Surprise 2", functionName: "menuItem2"}, {name: "Surprise 3", functionName: "menuItem3"} ];

// surprise3 is in another script

// After defining the menu entries, then you define the menu itself ss.addMenu("Surprises", menuEntries); }

function menuItem1() {
   var url = "https://gdata.youtube.com/feeds/api/videos?"
    + "q=skateboarding+dog"
    + "&start-index=21"
    + "&max-results=10"
    + "&v=2";
  var response = UrlFetchApp.fetch(url);
  Browser.msgBox(response);
}

function menuItem2() {
  var url = "https://gdata.youtube.com/feeds/api/videos?"
    + "q=skateboarding+dog"
    + "&start-index=21"
    + "&max-results=10"
    + "&v=2";
  Browser.msgBox(url);
}

but all this does is print "FetchReponse" in the box from menu1. So?

How do I get this into a browser? I must have something wrong with "deploy to web" selection, correct?

3
You should go through the more basic and fundamental tutorials available at developers.google.com/apps-script/articles so you'll know how GAS works. - Srik
I have been through the tutorial. What is this supposed to DO? Does it print? Display? make a sound? Display the link? Verify the link exits? I might be able to elicit the response if I know what it is supposed to DO. - Domarr
There are a few types of apps you can write using Apps Script: 1. Web Apps - these require a doGet. You return some HTML or a UiApp instance, and this gets rendered to a browser. 2. Apps that run in a spreadsheet - you can use things like msgBox for a popup dialog. You need to run these in the context of a Spreadsheet (the name "Browser" is misleading). You can either run these using the "Play" button or as a response to some event in the spreadsheet. - Ikai Lan

3 Answers

1
votes

The script does accomplish it's intended task.

The Google apps script UI has a debugger functionality. Try to use it to step thru the example snippet. after the variable is defined take a look at it's value. This wil help you to understand what is happening. It's true that the example itself (as is) does not do anything with the responce data, but that's up to you as a developer. With the value in variable 'responce' you could fill a listbox. But the code that does that is not supplied, thats up to you ;-) If you're not yet able to write that code, i agree with Srik's advise and take a look at the tutorials.

Lastly, this link kan help you with further questions about the API that's used in the example. https://developers.google.com/youtube/2.0/developers_guide_protocol#Standard_parameters

Hope this helps.

0
votes

Cut and pasted into a function and still get Unknown Macro doGet.

function myFunction() {
     var url = "https://gdata.youtube.com/feeds/api/videos?"
    + "q=skateboarding+dog"
    + "&start-index=21"
    + "&max-results=10"
    + "&v=2";
  var response = UrlFetchApp.fetch(url);
  Browser.msgBox(response);
}

Save it as a managed version. Then "Deploy as web app." Cut and paste the link AND the latest version and both of them give me "Unknown Macro doGet"

0
votes

Please read https://developers.google.com/apps-script/execution_web_apps before posting further.

Specifically the sentence: "In order to deploy a script as a web app, it must contain the doGet(e) function."

Then decide how to build your user interface: https://developers.google.com/apps-script/html_service or https://developers.google.com/apps-script/uiapp