googleapis Enables any app to access Google APIs through Oauth2 (including 2-legged auth for Google Marketplace)

  1. Requirements
  2. Installation
  3. Configuration
  4. Usage
  5. Todo
  6. Resources

This extensions provides a wrapper to googles google-api-php-client library providing an easy way to access google apis and authentication via 2- or 3-legged auth mechanisms. The extension is intended to enable any app to access google apis, perform authentication and get listed on google marketplace.

Requirements

Yii 1.1 or above

Installation

Copy the GoogleApis folder into extensions.

Configuration

'components' => array(
        // ...

        'GoogleApis' => array(
            'class' => 'ext.GoogleApis.GoogleApis',
            
            // See http://code.google.com/p/google-api-php-client/wiki/OAuth2
            'clientId' => 'YOUR_CLIENT_ID',
            'clientSecret' => 'YOUR_CLIENT_SECRET',
            'redirectUri' => 'YOUR_REDIRECT_URI',
            // // This is the API key for 'Simple API Access'
            'developerKey' => 'YOUR_DEVELOPER_KEY',
        ),
        // ...

Usage

/**
* @var apiPlusService $service
*/
$plus = Yii::app()->GoogleApis->serviceFactory('Plus');

/**
* @var apiClient $client
*/
$client = Yii::app()->GoogleApis->client;

Try {
  if(!isset(Yii::app()->session['auth_token']) 
  || is_null(Yii::app()->session['auth_token']))
    // You want to use a persistence layer like the DB for storing this along
    // with the current user
    Yii::app()->session['auth_token'] = $client->authenticate();
  else
    $activities = '';
    $client->setAccessToken(Yii::app()->session['auth_token']);
    $activities = $plus->activities->listActivities('me', 'public');
    print 'Your Activities: <pre>' . print_r($activities, true) . '</pre>';
} catch(Exception $e) {
    // This needs some love as not every exception means that the token
    // was invalidated
    Yii::app()->session['auth_token'] = null;
    throw $e;
}

Todo

Test and provide samples for Google Marketplace (2-legged-auth).

Resources

2 0
10 followers
2 208 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Web Service
Developed by: Daniel Khan
Created on: Jun 22, 2012
Last updated: 12 years ago

Downloads

show all

Related Extensions