2017 © Pedro Peláez
 

yii2-extension yii2-google-api-client-sa

A Yii2 wrapper for the official Google API PHP Client (In case used Service Account + DwD)

image

bscheshirwork/yii2-google-api-client-sa

A Yii2 wrapper for the official Google API PHP Client (In case used Service Account + DwD)

  • Friday, July 7, 2017
  • by bscheshirwork
  • Repository
  • 1 Watchers
  • 0 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

A Yii2 wrapper for the official Google API PHP Client (In case used Service Account + DwD)

For easily config and give you access to the service, (*1)

Installation

First you can register Google service account with DwD, user for this account and enable G suite access for this user id. api-client-library service-accounts, (*2)

Second - install wrapper and configure it use secret data., (*3)

The preferred way to install this extension is through composer., (*4)

Add, (*5)

"bscheshirwork/yii2-google-api-client-sa": "*"

to the require section of your composer.json file., (*6)

This package will also install the google/apiclient library., (*7)

Configuration

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., (*8)

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

    'components' => [
        // ..
        'gmail' => [
            'class' => 'bscheshirwork\gacsa\GoogleApiClient',
            'googleApplicationCredentials' => '@runtime/secret-place/myprojectname-privatekeyshortdigits.json',
            'api' => Google_Service_Gmail::class,
        ],

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

Usage

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

/**
 * @var $service Google_Service_Gmail
 */
$service = Yii::$app->gmail->getService(function(){
    $userToImpersonate = 'email@suitedomain.com';
    /** @var \Google_Client $client */
    $client->setSubject($userToImpersonate);
    return $client;
});

$messages = $service->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 = $service->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>";
        }
    }

}

Thanks Mehdi Achour, (*12)

The Versions

07/07 2017

dev-master

9999999-dev

A Yii2 wrapper for the official Google API PHP Client (In case used Service Account + DwD)

  Sources   Download

MIT

The Requires

 

by Avatar bscheshir

yii2 google service account dwd