1 / 27

Working with Databases (II) 靜宜大學資管系 楊子青

Working with Databases (II) 靜宜大學資管系 楊子青. Fusion Tables. 參考實例: Pizza Party with Fusion Tables for App Inventor 2 http://appinventor.mit.edu/explore/ai2/pizzaparty.html

darren
Download Presentation

Working with Databases (II) 靜宜大學資管系 楊子青

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Working with Databases (II)靜宜大學資管系 楊子青

  2. Fusion Tables • 參考實例:Pizza Party with Fusion Tables for App Inventor 2 • http://appinventor.mit.edu/explore/ai2/pizzaparty.html • A Fusion Table is a Google service to support the gathering, managing, sharing, and visualizing of data. Data are stored in multiple tables on Google‘s cloud (Google Drive雲端硬碟). • Individual tables can be merged if they contain a common column, and they can be easily visualized on maps and in various kinds of charts and graphs.

  3. 1. Creating your own Fusion Table • Creating your own Fusion Tables is as easy as creating a Google document. (請自行根據說明練習) 1. On the web, login to your Gmail account or any other Google service (e.g., Drive, YouTube). 2. Go to Google Drive and click the red Create button, you will see Fusion Table in the list of choices. Click Fusion Table. (If you do not see Fusion Table in the Google Drive Create menu, click Connect more apps. Scroll down until you find Fusion Table and click on it. Click the + Connect button, then click ok. Now, when you click on the Create button, Fusion Table should appear. If not, then you may need to contact your school's network administrator. See Troubleshooting section at the bottom of this page.) 3. You will be given a few different options for the new table. Select Create an empty table.

  4. Creating your own Fusion Table 4. You will see that the new table automatically comes with four columns. Change the column names for your Pizza app by going to Edit > Change Columns.You'll rename the four default columns to Date (type=Date), Name (type=Text), Pizza (type=Text), Drink (type=Text). Click save and then add a fifth column by going to the Edit > Add Column. Name this fifth column Comment (type=Text). . 5. Leave this window open so that you can come back and get the URL, which you'll need when you set up the properties of the WebViewer component in your app. 6. Click on the Share button (top right) to modify the table's permissions. For this tutorial, you can specify a few friends who will use the app. Only people who are explicitly given permission will be able to enter pizza party preferences through your app. (See note box immediately below this.)

  5. 練習:建立以下Fusion Table

  6. 2. Determining your Fusion Table URL and Table ID • To find your Fusion Table's URL: 1. In your browser, navigate to the new Fusion Table you just created. 2. Go to the menu and select Tools > Publish. 3. You'll see a notice saying: "This table is private and will not be visible". Click the blue link that says "Change Visibility". 4. In the list of "Who Has Access", click the blue "Change..." link next to "Private - Only people listed below..."

  7. Determining your Fusion Table URL and Table ID 5. Choose"Public on the Web" or "Anyone with the link". Either of these settings will work for this tutorial. In the future, you should decide this setting based on the sensitivity of your data. 6. Click the green Save button, then the blue Done button. 7. Back on the Fusion Table page, go to the menu bar and select Tools > Publish. Select the URL from the top text box (labeled "Send in an email or IM"), copy the URL and return to App Inventor. You will paste the URL into the definition block for the TABLE_URL (see below). 8. You can find the Table ID by browsing to your table, then selecting File>About this table in the menu.

  8. 練習:讀取Fusion Table網址

  9. 練習:讀取Fusion Table ID

  10. 利用WebViewer元件查看Fusion Table內容

  11. 程式碼及執行結果 Fusion Table網址

  12. 3. Getting an API Key • In order to use the FusiontablesControl Component you need to acquire a Google Applications Programming Interface (API) key, an API Key. 1. Go to your Google APIs Console (http://code.google.com/apis/console ) and log in with a google account if not already logged in. 2. On the left-hand menu, select the APIs & auth item. The top sub-item "APIs" should be selected. If not, select it. 3. In the list of APIs, scroll down to find the Fusion Tables API and click the toggle button to "on" (if it already says "on" then leave it as is.) 4. If prompted, read and agree to the terms of service. On the Devlopers Console API page you'll see that the on/off switch next to Fusion Tables API is now "On" and green.

  13. APIs: Fusion Tables API: ON

  14. Getting an API Key 5. Go back to the menu on the left of the screen and select the Credentials sub-item under "APIs & auth. 6. Your API key will show up under "Public API Access". If you do not see an API key, click the red button "Create New Key" and then click the "Android Key" button in the popup box. Don't worry about the pop-up box asking about SHA keys. Just click the "Create" button. Your API Key will be show up under "Key for Android applications". You will need set the "API Key" property of the Fusiontables Control component in any app that you make that uses Fusion Tables. (More info below.)

  15. API Key

  16. 新增資料至Fusion Table

  17. 初始設定程式碼 ForgetLogin() Method: Discards the user's account name, forcing them to re-authenticate when accessing a Fusion Table.

  18. 新增資料程式碼

  19. 用行動裝置測試,並使用自己的Gmail帳號登入,到雲端硬碟看Table用行動裝置測試,並使用自己的Gmail帳號登入,到雲端硬碟看Table

  20. 判斷是否新增資料成功

  21. 判斷是否新增資料成功 如果成功,result第一行為rowid

  22. 重新用行動裝置測試,並使用其他的Gmail帳號登入,則新增失敗重新用行動裝置測試,並使用其他的Gmail帳號登入,則新增失敗

  23. 增加個別使用者可以進行編輯

  24. 將使用者輸入的資料新增到資料庫

  25. SQL改用變數之程式碼

  26. 資料庫查詢

  27. 資料庫查詢程式碼,用行動裝置測試

More Related