# Embedding almost anything like a Twitter Search widget in new Google Sites with Google Apps Script

**Update:** Brad Dale has kindly created this [walkthrough video to help you with the setup](http://www.timetotalktech.com/2017/11/how-to-embed-your-twitter-feed-directly.html)

Previously I had fun [making a Google Calendar widget for the new version of Google Sites](https://hawksey.info/blog/2017/10/a-google-calendar-widget-for-google-sites-created-with-google-apps-script/). A comment that as a result of that post came from [Andy Cooper asked](https://plus.google.com/+MartinHawksey/posts/TSdzQ2ZPyzT) how to get a Twitter feed into Google Sites. Thanks to Google Apps Script this can actually be accomplished in a couple of lines of code. Apps Script has a [HTML Service which lets you create and serve HTML content](https://developers.google.com/apps-script/guides/html/). This means you can copy any embed code you get from a third party site like Twitter, publish it with Google Apps Script and then embed this in your new Google Site.

If you have some content you’d like to embed into a new Google Site that isn’t accepted by the ‘Embed URL’ feature in Sites you can try following these steps:

1. Go to [https://script.google.com ](https://script.google.com)and start a new script project
2. In the Script Editor add the following code:

```

function doGet() {
  return HtmlService.createHtmlOutputFromFile('Index')
                    .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}

```

You can replace the existing function in the Script Editor. The `doGet()` function is required to tell the script how to serve the page.

3. To add an HTML file to your Apps Script project, click **File &gt; New &gt; Html file** and enter the name ‘Index’ - this name must match the one given in the doGet() function
4. In the Index.html file paste the embed code between the tags. For example, to embed a Twitter search widget your code would [look like this](https://gist.github.com/mhawksey/4757cd59d46ded69cb593737cfe75042):
5. From the Script Editor click **File &gt; Rename** and give your project a name before clicking **File &gt; Save all**
6. To allow us to embed in Google Sites you need to [deploy your script as a web app](https://developers.google.com/apps-script/execution_web_apps#deploying) by selecting **Publish &gt; Deploy as web app**
7. In the dialog provide a project version name and select who has access to the app (for anyone to view select ‘Anyone, even anonymously’)
    ![Publish - Deploy as web app](https://hawksey.info/wp-content/uploads/2017/10/null-11.png)
8. When you click ‘**Deploy**’ you will be given a ‘Current web app URL’ which will be like `https://script.google.com/macros/s/RANDOM_ID_HERE/exec`
9. Open your Google Site and on the page you want to include your embedded object select **Insert &gt; Embed URL** and paste the ‘Current web app URL’ and then click **ADD**.

Here is an [example page with a Twitter search widget](https://sites.google.com/view/totallyunscripted/test) and the [source Google Apps Script code](https://script.google.com/d/1dcDIvSJ0FVJBbXBuMOzWRzqrHNQFQcjkM9UdihKw-ekl7F2GFnRnf_zs/edit?usp=drive_web).

**Important:** If you change the code in the Index.html file you need to repeat steps 6 and 7 for the changes to take effect.

This solution is not limited to Twitter and suitable for other services that require their own Javascript files.