Search code examples
parse-platformgoogle-apps-scriptnosql

Read/write to Parse Core db from Google Apps Script


I'm just starting to use Parse Core (as Google'e ScriptDB is being decommissioned soon) and am having some trouble.

So I'm able to get Parse Core db to read/write using just a standard HTML page as shown below:

<!doctype html>
<head>
  <meta charset="utf-8">

  <title>My Parse App</title>
  <meta name="description" content="My Parse App">
  <meta name="viewport" content="width=device-width">
  <link rel="stylesheet" href="css/reset.css">
  <link rel="stylesheet" href="css/styles.css">
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  <script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.2.18.min.js"></script>
</head>

<body>

  <div id="main">
    <h1>You're ready to use Parse!</h1>

    <p>Read the documentation and start building your JavaScript app:</p>

    <ul>
      <li><a href="https://www.parse.com/docs/js_guide">Parse JavaScript Guide</a></li>
      <li><a href="https://www.parse.com/docs/js">Parse JavaScript API Documentation</a></li>
    </ul>

    <div style="display:none" class="error">
      Looks like there was a problem saving the test object. Make sure you've set your application ID and javascript key correctly in the call to <code>Parse.initialize</code> in this file.
    </div>

    <div style="display:none" class="success">
      <p>We've also just created your first object using the following code:</p>

        <code>
          var TestObject = Parse.Object.extend("TestObject");<br/>
          var testObject = new TestObject();<br/>
          testObject.save({foo: "bar"});
        </code>
    </div>
  </div>

  <script type="text/javascript">
    Parse.initialize("PyMFUxyBxR8IDgndjZ378CeEXH2c6WLK1wK2JHYX", "IgiMfiuy3LFjzH0ehmyf5Rkti8AmVtwcGqc6nttN");

    var TestObject = Parse.Object.extend("TestObject");
    var testObject = new TestObject();
      testObject.save({foo: "bar"}, {
      success: function(object) {
        $(".success").show();
      },
      error: function(model, error) {
        $(".error").show();
      }
    });
  </script>
</body>

</html>

However, when I try to serve that up using the HtmlService shown below, I get no response from Parse. Parse Core.html basically has all of the code I have above ( only thing I changed was to remove the css calls).

function doGet() {
  var htmlPage = HtmlService.createTemplateFromFile('Parse Core.html')
                .evaluate()
                .setSandboxMode(HtmlService.SandboxMode.NATIVE)
                .setTitle('Parse Core Test');

  return htmlPage;
}

Solution

  • Link to ParseDb Library for Apps Script

    Here is the key to add the library: MxhsVzdWH6ZQMWWeAA9tObPxhMjh3Sh48

    Install that library and it allows you to use most of the same methods that were used by ScriptDb. As far as saving and querying go they almost identical. Make sure to read the Library's notes, how to add the applicationId and restApiKey. It is a little different that you can silo data by classes which must be defined in the call to Parse.

    Bruce here is leading the way on database connection for Apps Script, he has plenty of documentation on using Parse.com, and also his own DbConncection Drive that would allow you to use a number of back-end systems.

    Excel Liberation - Bruce's Site.