Google App Engine Google APIs OAuth Facebook Graph API Twitter Bootstrap Google Developer Group Presentation & Workshop @ Albertian Institute of Science & Technology – 19th October 2013 Shashidhar Gurumurthy shashidhar.gurumurthy@gmail.com https://cloud.google.com/
Agenda Session Objectives App Engine Overview Environment Setup App Engine Services OAuth Google APIs Facebook APIs References Play on shashi-demo.appspot.com
Session Objectives Describe App Engine & its offerings Get you started on App Engine development using Java Usage of commonly used App Engine services OAuth Working with Google APIs Working with Facebook APIs Help you develop your first App Engine application and use few Google & Facebook APIs
Session Objectives – Prerequisites Familiarity with Servlet development using a Servlet container such as Tomcat is assumed Some familiarity with Eclipse IDE That’s it… that’s all you need to get started on developing awesome apps with Google App Engine. Objectives
Session Objectives – What’s not covered Google App Engine applications can be written in Python and Go programming languages as well. This session uses Java. All Services provided are not covered due to time constraints Objectives
So… what is Google App Engine Overview Google App Engine lets you: Run web applications on Google’s infrastructure Easy to build, maintain and scale No servers to maintain – just upload your application Costs nothing to get started: All applications get a free limit on resources When billing is enabled for an application, free limits are raised but you still pay only for resource usage above free levels Applications run in a secure environment with limited access to underlying operating system Applications can only access other computers on the internet through provided URL Fetch and Email services Applications cannot write to the file systems Application code only runs in response to a web request, queued task or a scheduled task
The Java Runtime Environment Overview Java runtime environment uses Java 6 (Java 7 support is experimental with SDK 1.7.5+) App Engine Java SDK supports Java 5 or 6 Java Servlet and JSPs The SDK provides implementations of Java Data Objects (JDO) & Java Persistence API (JPA) interfaces for interaction with App Engine Datastore JavaMail API can be used to send mail with App Engine Mail service java.net.HTTP APIs access the App Engine URL Fetch service
Development Workflow Overview App Engine SDK includes tools for local emulation of App Engine services SDK includes tools for uploading application to App Engine The App Engine admin console is the web-based interface for managing applications running on the App Engine. Use it to: Create new apps Configure domain names Change which version of application is live Examine logs Browse application datastore View Memcache App Engine Console
App Engine Information on web Environment Setup Setup Install Java SDK (1.7 or 1.6) – 1.7 is experimental and available on App Engine SDK 1.7.5+ only If using Eclipse, install Google Plugin for Eclipse If not using Eclipse, download App Engine Java SDK In this case you will also need Apache Ant to enable you to interact with App Engine via command line interface – we will not cover this case. Setup details: https://developers.google.com/appengine/docs/java/gettingstarted/installing App Engine Information on web
Services – Users Services App Engine applications can authenticate using one of three methods: Google Accounts Accounts on Google Apps Domains OpenID identifier – federated authentication Application can access a signed in user’s email address (or OpenID identifier) The app can detect whether the current user is an administrator
Services – Datastore Services The App Engine Datastore is a schemaless object datastore The Datastore holds data objects known as entities Each entity is identified by its kind which categorizes the entity for the purpose of queries, and a key that uniquely identifies it within its kind The Datastore can execute multiple operations in a single transaction While the Datastore interface has similar features as traditional relational databases, it differs in the way it describes relationships between data objects Entities of the same kind can have different properties
Services – Java Datastore API The App Engine Java SDK provides a low-level Datastore API with simple operations on entities The SDK also includes implementation of the Java Data Objects (JDO) and Java Persistence API (JPA) interfaces for modeling and persisting data App Engine Datastore service is a large area of study We will briefly review JDO for persisting and querying entities
Services – Scheduled Tasks The App Engine Cron Service allows scheduling of tasks that operate at defined times or regular intervals A Cron job will invoke a URL using an HTTP GET request at a given time of day A cron.xml file in WEB-INF directory of the application controls cron The Admin Console allows you to view the state of your cron jobs The dev appserver does not automatically run the cron jobs
Services – Mail App Engine applications can send email messages Apps can receive emails at various addresses Apps send messages using the Mail service Apps receive messages in the form of HTTP requests initiated by App Engine and posted to the app The Mail service Java API supports the JavaMail interface for sending email messages The development server does not send email messages
Services – URL Fetch Services App Engine applications can fetch resources and communicate with other hosts over the internet using HTTP & HTTPS requests Apps use URL Fetch service to make requests The URL Fetch service uses Google’s network infrastructure for efficiency and scaling purposes Apps use java.net.URLConnection and related classes to make connections
Services – Task Queues Services Applications can perform work outside of a user request. The application adds tasks to task queues to be executed later Two types of queues: Push Queues function within App Engine environment. Configure a queue and add tasks to it. App Engine handles the rest. Pull Queues allows consumers inside or outside of App Engine environment to process tasks In this case application needs to scale workers based on processing volume
Services – Google Cloud Storage The Google Cloud Storage offers another method for your application to store and serve data Similar to AWS S3 Access via a RESTful API as well as Cloud Storage Java API for Google App Engine
Services – Memcache Distributed in-memory data cache Speed up common datastore queries If many requests make the same query with the same parameters, app can cache the results in memcache
Services – Multitenancy Multitenancy refers to a software architecture whereby one instance of an application serves many client organization Namespaces API allows you to compartmentalize Google App Engine data App Engine supports Namespaces in the following APIs Datastore Memcache Task Queue
Services – Google Cloud Endpoints Consists of tools, libraries and capabilities to generate endpoints and client libraries from an App Engine backend to simplify client access to that back end. Introduced in Feb 2013 with SDK 1.7.5
Services – Others App Identity Identifying itself Asserting identity to Google APIs and other systems Blobstore: Datastore allows blobs of max 1M. For storing larger objects, use Blobstore Channel: Use to create persistent connection to send messages to Javascript client in real time. Images: Manipulate image data using dedicated image service Logs: Provides access to request and application logs OAuth: Use App Engine application as OAuth service provider Capabilities, Search, Prospective Search & XMPP (IM)
Google APIs & OAuth Google provides access to many of its services via APIs You can use these APIs within your applications Most of the APIs require authenticated access; OAuth provides the authentication mechanism OAuth also provides a mechanism to gain access to private data via scoped authorization Steps to use Google API: Define a project on Google API console Select the required services Create OAuth client id ( & secret) Use the OAuth flow to get access token Send Access token in request header of the HTTP call to Google API OAuth Playground Google APIs Console
Google OAuth Flow (for Web Server Applications)
Facebook API Usage Similar access mechanism as Google API Uses OAuth for authorization Steps to use Facebook API: Define a Facebook App on developers.facebook.com This gives you App ID & App Secret Use the App ID & App Secret along with required permissions to get access token Send Access token as request parameter in the HTTP call to Facebook API Facebook Developers
What else do I need? Something to make the UI look better Frameworks for responsive client Best ones to start with jQuery Twitter Bootstrap Some More Mustache Templates jQuery Mobile
Demo – Sample Starter Applications Starter Apps which you can use to begin developing App Engine application using Google APIs or Facebook APIs Google API used – Calendar API to get Calendar list Facebook API used – Get logged in user’s profile How to use? To learn, copy/paste piece by piece into a new App Engine project OR Import whole project and enhance / modify
Environment Setup Create App Engine Project & Deploy Use Google and/or Let’s Play Environment Setup Create App Engine Project & Deploy Use Google and/or Facebook API In Your Project
References Google App Engine Home: https://developers.google.com/appengine/ App Engine Java Home: https://developers.google.com/appengine/docs/java/overview App Engine Admin Console: https://appengine.google.com/ Google APIs Console: https://code.google.com/apis/console Google OAuth documentation & flow: https://developers.google.com/accounts/docs/OAuth2 OAuth Playground: https://developers.google.com/oauthplayground/ Facebook Developers: https://developers.facebook.com Demo Source Code: Google APIs starter project: http://commondatastorage.googleapis.com/sessionmaterials/AppEngineStartupProj ect.zip Google + Facebook APIs starter project: http://commondatastorage.googleapis.com/sessionmaterials/AppEnginePlusFaceb ookStartupProject.zip