Appendix B: Creating Your Own TinyWebDB

The TinyWebDB component that is used in Chapter 7 stores and retrieves information across the Internet. An App Inventor application can use the TinyWebDB to maintain a database off of the Android device. This is accomplished by sending requests to store and get information from a database that resides on a Web server. The Web server where the TinyWebDB database resides must be running the TinyWebDB service. The TinyWebDB service listens for and responds to the GET and STORE requests.

These instructions help you install and configure the TinyWebDB service on a free Google Apps server. The instructions include downloading a version of the TinyWebDB service that has been built with the Python programming language. You can run the TinyWebDB service on your own Web service or your local computer. Instructions for customizing the Python code to run on your own server are beyond the scope of this book. If you are interested in customizing the TinyWebDB, research customizations on the App Inventor forum and the App Inventor Resources site at http://appinventor.googlelabs.com and https://sites.google.com/site/appinventorresources/.

Before beginning, download the following files:

• The Python App Engine for Google App Engine from code.google.com/appengine/downloads.html#Google_App_Engine_SDK_for_Python

• The Python code for the TinyWebDB Web service from http://appinventor.googlelabs.com/learn/reference/other/tinywebdbassets/customtinywebdb.zip

The following steps allow you to run your own Web service to receive data and send data to your TinyWebDB component. You need to have a URL to point the component toward. The default URL for the component is a test database that is public and is regularly deleted.

Note.eps

These steps guide you through setting up a service on Google’s App Engine host service. However, Google’s App Engine is not the only option for hosting the service: It can also be hosted on a server of your own. Hosting the service on your own server requires significantly more knowledge. The Python script that responds to TinyWebDB can be altered to run on your own Python framework.

A few Java ports exist for the Web service as well. You can find discussions about implementing the Java versions of the TinyWebDB service in the Google App Inventor forum at http://appinventor.googlelabs.com/forum/.

The high-level steps for the process are as follows:

1. Set up your free Google App Engine account.

2. Install the Google App Engine SDK (software development kit) on your local computer.

3. Create your application on Google App Engine.

4. Extract the Python code for the TinyWebDB service to your local computer.

5. Edit the Python code to be unique to your application on the App Engine.

6. Upload the customized Python code to your App Engine account.

Setting Up Your Google App Engine

I give more details on these steps in the remainder of this appendix. First, you need to sign up for a Google App Engine account:

1. Navigate your Web browser to http://code.google.com/appengine/.

2. Click on the Sign Up for an App Engine Account link. See Figure B-1.

Figure B-1: The Google App Engine sign-up

9781119991335-fgab01.eps

Next, install and set up the Google App Engine:

1. Install the appropriate Python SDK package from the App Engine download files. For Windows machines, the file is called GoogleAppEngine-1.#.#.msi. This step starts the Google App Engine Install wizard.

2. Click Next on the Welcome screen. If you do not have Python installed on your local computer, click the button to install Python and follow the prompts.

3. After the Python installation is complete, return to the Google App Engine SDK set up and Accept the license agreement on the end user license agreement page.

4. Click Next on the Destination Folder window.

5. Click Install on the Ready to Install page.

6. When the installation completes, run the Google App Engine launcher. (See Figure B-2.)

Figure B-2: The App Engine console

9781119991335-fgab02.eps

7. Click the Dashboard button on the console. This brings up the log-in for the Google App Engine.

8. Enter your Google credentials for the log-in.

For most people, their Google account is their Gmail username password. If you do not have a Gmail account or a Google Apps account, you need to sign up for Gmail. Both the App Engine and App Inventor require a Google account. You can use the same log-in to log in to both App Inventor and App Engine.

9. Click the Create Application button.

10. If you have not done so previously, you are asked to verify your account using an SMS message.

11. After you have verified your account, create an application.

12. Select an application identifier. This is part of your TinyWebDB service URL. The identifier you choose must be unique across all App Engine apps. Your URL is your application identifier followed by appspot.com. If you select an application identifier of 0805App, for example, your URL is 0805app.appspot.com.

13. Write down your application identifier for safekeeping.

14. Select an application title. Any descriptive text will do.

15. Scroll down and click the Create Application button.

Now you have a blank application ready to put your Python code into.

Customizing and Installing the TinyWebDB Service

Next, unzip the Python code, customize it, and load it to your App Engine account using the App Engine console:

1. Unzip the customtinywebdb.zip file you downloaded from http://appinventor.googlelabs.com/learn/reference/other/tinywebdbassets/customtinywebdb.zip into an easy-to-find location.

2. Locate the app.yaml file from the files you extracted from customtinywebdb.zip and open the app.yaml file with Notepad. You see the text shown in Figure B-3.

Figure B-3: The app.yaml file

9781119991335-fgab03.eps

3. Change the customtinywebdb text to match your unique application identifier. Using the previous example, the app.yaml file would look like Figure B-4.

Figure B-4: The customized app.yaml file

9781119991335-fgab04.eps

4. Save the app.yaml file and close Notepad.

The next step is to upload the application to Google App Engine.

1. Open the Google App Engine launcher from either the desktop shortcut or your Start menu.

2. Click File on the toolbar and select Create New Application.

3. Enter your application identifier in the Application Name field. Using the previous example, you would enter 0805app.

4. Click the Browse button next to the Parent Directory field.

5. Navigate to the customtinywebdb folder you extracted from the customtinywebdb.zip.

6. Select the folder and click OK.

7. Click Create.

Now you see your application in the main screen of the launcher.

8. Select your application in the main launcher window and click the Deploy button.

9. Enter your Google account credentials whether Gmail or Google Apps account in the pop-up dialog.

10. Click OK.

A deployment window appears and the deployment starts. When a message appears that says, You can close this window now, close the window and close the launcher.

Test to see whether the service is running:

1. Open a Web browser and enter your application identifier followed by .appspot.com. Using this example, you would enter 0805app.appspot.com and press Enter.

2. Your app should serve a page like the one in Figure B-5.

3. If you get a Web page with Hello World, give the application a few minutes to deploy and try again. It may take a few minutes before it responds.

Figure B-5: The running TinyWebDB service

9781119991335-fgab05.tif

Now you can customize your App Inventor application to send and receive data from your custom TinyWebDB service:

1. Drag and drop the TinyWebDB component into your application.

2. In the Properties column, change the ServiceURL to point to your custom application. In this example, you would change it to http://0805app.appspot.com.

Now you can use the GET and SEND values to send and retrieve data.

Note.eps

The data sent and received from the TinyWebDB service is not secured and a determined snoop could find your appspot.com URL and snoop through the data. Using a random string for the app spot name can help secure your data to some extent, but you should always think of the TinyWebDB service as not secured.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
35.170.81.33