Skip to content

uchilaka/GoogleGlassComponent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

DISCLAIMER

This code is provided AS-IS. It is the result of work done exploring the Google Glass platform and is inspired by code provided along with the Google Glass Mirror API documentation available @ https://developers.google.com/glass/develop/mirror/quickstart/php. For a Quick Start guide to using the Google Glass Mirror API, visit https://developers.google.com/glass/develop/mirror/quickstart/.

REQUIREMENTS

INSTALLATION

Copy the component to your /<Application Root>/app/Controller/Component/ directory, or any other directory bootstrapped to search for components.

Update the paths in the component file to those for each of the required classes. BE SURE TO MAKE THE PATH TO THE SQLITE DATBASE WRITABLE BY YOUR WEB USER ACCOUNT.

Replace the paths to both the Google_Oauth2Service and Google_Client class files with the correct path on your server - e.g. /var/www/libraries/google/google-api-client/src/contrib/<ClassFile> assuming that is where you have the Google API library installed on your server

That's it! You're ready to start using the component within your CakePHP controllers.

USING THE COMPONENT

Include the component name in your $components array

    public $components = array('GoogleOauth2');

Next, use the connect() method to initialize the component when you are ready to attempt authentication against Google ID. See the method reference below for accepted arguments.

LOADING COMPONENTS ON THE FLY

You can load the component on the fly in your CakePHP application using the following syntax:

$this->GoogleAuth = $this->Components->load('GoogleGlass');

FUNCTIONS

connect($controller, $config, $scopes, $api_mode)

This method is most likey be well used within your project. It initializes your authentication attempt againt the user's Google ID, and accepts the following arguments:

controller: Use the $this variable to pass your controller into the component for controller-level callbacks

config: This is an associative array with the following parameters:

client_id: Your Google API client ID

client_secret: Your Google API secret

redirect_url: Your success redirect url once the authentication action is completed. This url MUST be included in the list of accepted callbacks in your google console

api_mode: This is a boolean variable. If set to true, the component will return an associative array with a success index that indicates whether the auth attempt was successful or not. This will be useful if you are authenticating via an API and would like to parse the associate array to a JSON string (for instance) instead of the auto-redirect action.

isReady()

This returns true or false after a connect() call for a success or failure to authenticate.

getAuthUrl()

Returns the authentication Url against Google's OAuth API. Is useful if you are handling redirection manually. In this case, the api_mode variable of your connect() function can come in handy to turn off the auto-redirect when authentication is needed.

getUser()

Will return an associate array of the session user data.

getUserId()

Will return the Google User ID from the session user array.

cleanUser()

Useful for logging out. Call in your logout() controller function to delete the google user data from the session.

getTokens()

Returns a JSON string of the tokens returned on successful authentication and stored in the session array.

init_db()

Function for initializing the sqlite database.

get_credentials($userid)

Will return a JSON string with the credentials from the Google_Client authentication in the connect() method.

  • userid: This is the Google ID of your authenticated user, stored in the session.

store_credentials($userid, $token)

Will store the $token passed against the $userid in the credentials table. USE WITH CAUTION - PREFERRABLY WITHIN THE authenticate() PRIVATE METHOD ONLY.

  • userid: This is the Google ID of your authenticated user, stored in the session.
  • $token: The JSON format string returned after a successul authentication

verify_credentials($controller, $credentials, $api_mode)

Used by the authenticate method to verify the session-stored credentials when a page is re-loaded.

  • controller: Pass your host controller using the $this variable in CakePHP
  • credentials: This is the JSON format string returned as the token which you exchange for your code in the OAuth flow.
  • api_mode: used to control the auto-redirect function of the authenticate() and connect() methods. Will return an associate array with a success index instead.

bootstrap_new_user() *Customize

This method will instantiate a new user as well as insert a welcome slide in their Glass Timeline. BE SURE TO CHANGE THE PARAMETERS HERE TO THOSE FOR YOUR PURPOSES.

insert_contact($contact_name, $display_name, $icon_url)

Inserts a contact for the authenticated user

  • contact_name: The name of the contact to be inserted
  • display_name: The display name.
  • icon_url: The web link for an icon to represent this contact.

subscribe_to_notifications($collection, $user_token, $callback_url)

collection: A string representing the collection you want to insert a notificaiton to e.g. "timeline"

user_token: as returned by the getTokens() method

callback_url: the resource link for Google glass regarding this notification

insert_timeline_item($timeline_item [, $content_type, $attachment ] )

inserts a pre-built timeline item into the user's glass timeline. The $timeline_item variable must be of type Google_TimelineItem. See the documentation for the Glass Mirror API for details: https://developers.google.com/glass/v1/reference/timeline

  • timeline_item: An instance of the Google_TimelineItem class with parameters populated using the GET methods.
  • content_type (optional): The MIME type of the timeline item. For a list of allowed MIME types, refer to the Mirror API Documentation: https://developers.google.com/glass/v1/reference/timeline/insert. For details, review the Mirror API documentation, specifically the functions in the Google_TimelineItem class, defined in the Google_MirrorService file in the Google PHP API: https://code.google.com/p/google-api-php-client/.
  • attachment (optional): An attachment for the timeline item. For details, review the Mirror API documentation, specifically the functions in the Google_TimelineItem class, defined in the Google_MirrorService file in the Google PHP API: https://code.google.com/p/google-api-php-client/.

delete_timeline_item($service, $item_id)

Deletes an item from the user's timeline.

  • service: An instance of the Google_MirrorService class as returned by the getService() method.
  • item_id:The ID for the item to be deleted.

delete_contact($contact_id)

Delete a contact.

  • contact_id: The ID for the stored contact.

QUESTIONS?

Reach out @ https://twitter.com/websiteinapage. I'll do my best to respond in a timely fasion.

About

CakePHP Component for the Google Glass Mirror API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages