This is a sample Android application that demonstrates getting a valid OAuth2 token for use with the Google Glass Mirror API without creating a web service.
This sample application depends on the Google Play Services library project.
You'll need to first clone the repository to your workstation. The Google Play
Services library is not included in this repository, so you'll need to copy it
to the libraries/GooglePlayServices
directory:
$ cp -r $ANDROID_HOME/extras/google/google_play_services/libproject/google-play-services_lib/* libraries/GooglePlayServices
Note: A build.gradle file has been included for your convenience in the
libraries/GooglePlayServices
directory.
After copying the Google Play Services library to the repo you should be able to build and run the project from the command-line using the typical Gradle build commands:
$ ./gradlew installDebug
Google verifies API requests sent from Android devices by matching the package name and SHA1 signing certificate fingerprint with those defined by the application.
You need to generate the signing certificate's SHA-1 fingerprint by running the following keytool command in a terminal:
$ keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
Note: The above command expects you to be signing your app with the Android debug certificate.
Before the sample code will work you'll need to enable the Mirror API for your app. You can do this in your app's API project in the Google APIs Console.
- Create an API project in the Google APIs Console.
- Select the Services tab in your API project, and enable the Mirror API.
- Select the API Access tab in your API project, and click Create an OAuth 2.0 client ID.
- In the Branding Information section, provide a name for your application (e.g. "Mirror Quickstart Sample"), and click Next.
- Providing a product logo or a homepage URL is optional.
- In the Client ID Settings section, do the following:
- Select Installed application for the Application type.
- Select Android for the Installed application type.
- Type "com.example.mirror.android" in Package name.
- Paste the SHA-1 fingerprint generated in Step 1 into the Signing certificate fingerprint.
- Click Create Client ID.
Note: The Mirror API is currently only available to developers with Glass hardware. If you don't see it in your API list, you'll need to contact the Glass support and have it enabled.
This code is released under the Apache 2.0 license.