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.
Yii 1.1 or above
Copy the GoogleApis folder into extensions.
'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', ), // ...
/** * @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; }
Test and provide samples for Google Marketplace (2-legged-auth).
Total 4 comments
I need to look into it.
Thank you.
Any chance I could use this ext to read-write docs on google drive?
I believe you need a $client->setAccessToken(Yii::app()->session['auth_token']);
inside the else block
Leave a comment
Please login to leave your comment.