2017 © Pedro Peláez
 

yii2-extension yii2-google-apiclient

A Yii2 wrapper for the official Google API PHP Client

image

idk/yii2-google-apiclient

A Yii2 wrapper for the official Google API PHP Client

  • Monday, January 15, 2018
  • by machour
  • Repository
  • 3 Watchers
  • 3 Stars
  • 412 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 57 % Grown

The README.md

yii2-google-apiclient

A Yii2 wrapper for the official Google API PHP Client., (*1)

Latest Stable Version Latest Unstable Version License Total Downloads, (*2)

This extension comes with:, (*3)

  • A console utility to generate your credentials files
  • A component that will take care of the authentication, and give you access to the service

Installation

The preferred method of installation is via Packagist and Composer. Run the following command to install the package and add it as a requirement to your project's composer.json:, (*4)

composer require idk/yii2-google-apiclient

Configuration

Credentials file, (*5)

In order to use this extension, you will be needing a credentials file for your Google Application., (*6)

You can generate this file using the provided console utility:, (*7)

  • Configure the module in config/console.php:
'bootstrap' => ['log', 'yii2gac'],
'modules' => [
    'yii2gac' => [
        'class' => 'idk\yii2\google\apiclient\Module',
    ],
],
  • Use the /configure sub command:
./yii yii2gac/configure <clientSecretPath> [api]

where clientSecretPath is the path to your secret JSON file obtained from the Google Console and api the api identifier (it will be prompted for if not provided)., (*8)

Components, (*9)

You application may use as much Google_Service instances as you need, by adding an entry into the components index of the Yii configuration array., (*10)

Here's how to setup GMail for example, a usage sample is provided below., (*11)

    'components' => [
        // ..
        'google' => [
            'class' => 'idk\yii2\google\apiclient\components\GoogleApiClient',
            'credentialsPath' => '@runtime/google-apiclient/auth.json',
            'clientSecretPath' => '@runtime/google-apiclient/secret.json',
        ],

This will enable you to access the GMail authenticated service Yii::$app->google->getService() in your application., (*12)

Sample usage

Displaying your newest message subject on GMail, (*13)

$gmail = new \Google_Service_Gmail(Yii::$app->google->getService());

$messages = $gmail->users_messages->listUsersMessages('me', [
    'maxResults' => 1,
    'labelIds' => 'INBOX',
]);
$list = $messages->getMessages();


if (count($list) == 0) {
    echo "You have no emails in your INBOX .. how did you achieve that ??";
} else {
    $messageId = $list[0]->getId(); // Grab first Message

    $message = $gmail->users_messages->get('me', $messageId, ['format' => 'full']);

    $messagePayload = $message->getPayload();
    $headers = $messagePayload->getHeaders();

    echo "Your last email subject is: ";
    foreach ($headers as $header) {
        if ($header->name == 'Subject') {
            echo "<b>" . $header->value . "</b>";
        }
    }

}

The Versions

15/01 2018

dev-master

9999999-dev https://github.com/idk-tn/yii2-google-apiclient

A Yii2 wrapper for the official Google API PHP Client

  Sources   Download

MIT

The Requires

 

api yii2 google

17/11 2017

1.1.0

1.1.0.0 https://github.com/idk-tn/yii2-google-apiclient

A Yii2 wrapper for the official Google API PHP Client

  Sources   Download

MIT

The Requires

 

api yii2 google