Thursday, July 3, 2014

Mirror API and Google App engine


The Google Mirror API allows you to build web-based services that interact with Google Glass. It provides this functionality over a cloud-based API and does not require running code on Glass( Read More). In this post am going to discuss about how to create a Mirror API hello world app and deploy it to Google AppEngine.

  1. Create Google App Engine Project
  2. Create Google API console project
  3. Install Google App Engine Plugin for Eclipse
  4. Develop Web application with mirror API
  5. Deploy web app to App Engine
1. Create Google App Engine Project
Create a application in https://appengine.google.com, and note down the application identifier we are going to use this identifier in further steps.



2. Create Google API console project
Follow mirror API java quick start guide to create Google APIs console project finally you will get Client id and Client secret note down these two values we are going to use this values in future steps.

3. Install Google App Engine Plugin for Eclipse
Follow this Google document to install app engine plugin in Eclipse.

4. Develop Web application with Mirror API
a. Before start development download this mirror quick start java project from GitHub. Now create a new App Engine project in your Eclipse. Follow these steps to create new app engine project.
b. Add Google Mirror API to your project - Right click on the Project > Google > Add Google APIs > Choose Google Mirror API > Click Finish
c. Enable sessions on GAE - add the following line in the war/WEB-INF/appengine-web.xml file
true
d. Copy content of quickstart project web.xml to new project war/WEB-INF/web.xml
e. Add Java classes - Copy all the java classes from quickstart project to your new project (com.titut.helloworld)
f. Add Java class for Authentication Configuration - Create new class (AuthSettings.java) and add CLIENT_ID and CLIENT_SECRET strings you have noted from Google APIs Console credential section.
public class AuthSettings {
    public static String CLIENT_ID = "546776174828-250jkc2net680pqsta97bk69epllge81.apps.googleusercontent.com"; 
    public static String CLIENT_SECRET = "OK6k0lxIBlorx87TUnUBQObg";
}
Also do necessary changes in AuthUti.java class
g. Copy index.jsp into war directory and delete existing index.html file. Also change import class reference in index.jsp file.
h. Copy static folder and place inside the war.
i. Download common-lang3.jar and add to your build path.
j. Now right click your project -> Run as web application, now your project will be running in localhost you can check it in http://localhost:8080

5. Deploy web app to App Engine
a. Add your app engine identifier(which you obtained in Step 1 in war/WEB-INF/appengine-web.xml file
    canvas-fulcrum-534
b. Change the redirect URIs in API console

c. Change the war/WEB-INF/logging.properties to
    .level = INFO
So that you can see log messages in Google AppEngine console
Now right click your project -> Google -> Deploy to App engine

Thats it now you successfully deployed your Mirror API app in Google App engine.

Source Code : https://github.com/railskarthi/MirrorAPIHelloWord
AppEngine URL : https://canvas-fulcrum-534.appspot.com
Reference : http://www.slideshare.net/endovert/glass-classtutorial2-mirrorapi

 

Copyright @ 2013 Google Glass Tutorials.