Yii 1.1: googleapis

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

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

Total 5 comments

#15128 report it
Shahcheraghean at 2013/10/10 03:05am
form api

Thank you for the extension. How can i use form api in the extension?

#11113 report it
Daniel Khan at 2012/12/17 03:34pm
@radoo

I need to look into it.

#11112 report it
Daniel Khan at 2012/12/17 03:30pm
@docnewman

Thank you.

#10929 report it
radoo at 2012/12/04 05:04am
acccess to docs on google drive

Any chance I could use this ext to read-write docs on google drive?

#10903 report it
docnewman at 2012/12/01 11:49pm
Typo?

I believe you need a $client->setAccessToken(Yii::app()->session['auth_token']);

inside the else block

Leave a comment

Please to leave your comment.

Create extension