PHPackages                             simplon/gplus - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. simplon/gplus

ActiveLibrary[HTTP &amp; Networking](/categories/http)

simplon/gplus
=============

Google+ API Library

0.0.5(12y ago)09971MITPHPPHP &gt;=5.4

Since Feb 19Pushed 12y agoCompare

[ Source](https://github.com/fightbulc/simplon_gplus)[ Packagist](https://packagist.org/packages/simplon/gplus)[ Docs](https://github.com/fightbulc/simplon_gplus)[ RSS](/packages/simplon-gplus/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (2)Versions (6)Used By (0)

```
     _                 _                           _
 ___(_)_ __ ___  _ __ | | ___  _ __     __ _ _ __ | |_   _ ___
/ __| | '_ ` _ \| '_ \| |/ _ \| '_ \   / _` | '_ \| | | | / __|
\__ \ | | | | | | |_) | | (_) | | | | | (_| | |_) | | |_| \__ \
|___/_|_| |_| |_| .__/|_|\___/|_| |_|  \__, | .__/|_|\__,_|___/
                |_|                    |___/|_|
```

Simplon/Gplus
=============

[](#simplongplus)

1. **Installing**
2. **Setup Gplus module**
    2.1. Create authentication container
    2.2. Create Gplus module instance
3. **Usage**
    3.1. Request authentication url
    3.2. Request AccessToken
    3.3. Read user profile data
    3.4. Refresh AccessToken manually
4. **Full example**

---

### Dependecies

[](#dependecies)

- PHP &gt;= 5.4
- CURL

---

1. Installing
-------------

[](#1-installing)

Install easy via composer:

```
{
  "require": {
    "simplon/gplus": "0.0.*"
  }
}
```

---

2. Setup Gplus module
---------------------

[](#2-setup-gplus-module)

For all calls we wanna make we need to initialise our Gplus module with our `Google Api credentials`. If you happen to miss these credentials hop over to [Google's console](https://cloud.google.com/console) and create them.

### 2.1. Create authentication container

[](#21-create-authentication-container)

We use a [value object](http://css.dzone.com/books/practical-php-patterns/basic/practical-php-patterns-value) to hold our credentials. I love value objects because of their clear communication what kind of data they hold.

```
$authVo = (new \Simplon\Gplus\Vo\GplusAuthVo())
    ->setClientId(CLIENT_ID)
    ->setClientSecret(CLIENT_SECRET)
    ->setUrlRedirect(AUTH_URL_REDIRECT); // URL to which google redirects after authentication
```

**Enforce authentication prompt:**By default Google determines automatically if the has to approve your app. This means that the first time the user will see a prompt while on the second time the user would be directly redirected to the given `AUTH_URL_REDIRECT`.

For testing purposes I found it ideal to enforce the constant appearance of the prompt upon authentication. To enable this the following should work just fine:

```
$authVo = (new \Simplon\Gplus\Vo\GplusAuthVo())
    ->setClientId(CLIENT_ID)
    ->setClientSecret(CLIENT_SECRET)
    ->setUrlRedirect(AUTH_URL_REDIRECT);
    ->forceApprovalPrompt();
```

### 2.2. Create Gplus module instance

[](#22-create-gplus-module-instance)

Alright, now that we have our `GplusAuthVo` we can proceed to create our `Gplus` instance.

```
// pass our prior created authVo
$gplus = new \Simplon\Gplus\Gplus($authVo);
```

---

3. Usage
--------

[](#3-usage)

This scenario shows an authentication flow initialised via the server. If you happen to have already an `accessToken` and `refreshToken` you can jump straight to point `3.3`.

**Remember:** We need the prior created Gplus instance `$gplus` in order to interact with Google's API.

### 3.1. Request authentication url

[](#31-request-authentication-url)

We need an `authentication url` which we can pass to a web client which in turn should open it. We also need to tell Google for which scopes we request permission. Here is a list of [possible scopes](https://developers.google.com/+/api/oauth#login-scopes).

For this example we will request access to the `user's email` and his/her `profile data`. **Note:** In the following example I use a set of `class constants` which helps me to avoid typos etc. I suggest you do the same since it helps you to keep track of data within your code.

```
// with class constants (highly recommended)
$scopes = [
    \Simplon\Gplus\GplusConstants::AUTH_SCOPE_EMAIL,
    \Simplon\Gplus\GplusConstants::AUTH_SCOPE_PROFILE,
];

// without class constants
$scopes = ['email', 'profile',];
```

Now, lets fetch the `authentication url`. This URL should be passed to the web client which redirects the user to Google's authentication process.

```
// pass prior defined $scopes
$urlAuth = $gplus->getAuthUrl($scopes);
```

### 3.2. Request AccessToken

[](#32-request-accesstoken)

When everything went fine Google will redirect to our prior defined `AUTH_URL_REDIRECT` with a GET parameter named `code` which is attached to the url. We will use this code now to exchange it for a valid `accessToken`.

```
if(isset($_GET['code']))
{
    $gplusRequestAccessTokenVo = $gplus->requestAccessToken($_GET['code']);

    if($gplusRequestAccessTokenVo !== FALSE)
    {
        echo $gplusRequestAccessTokenVo->getAccessToken();
        echo $gplusRequestAccessTokenVo->getRefreshToken();
    }
}
```

If everything went fine we will receive a bunch of data via `$gplusRequestAccessTokenVo` which is another value object. Actually we are mostly interested in only two variables: `accessToken` and its `refreshToken`.

The `accessToken` will give us access to the requested `scopes` while the `refreshToken` will renew the `accessToken` as soon as it ended its life time (2 hours). Therefore, its important to save both tokens and never to lose the `refreshToken`.

### 3.3. Read user profile data

[](#33-read-user-profile-data)

In order to read a user's profile data we need the aforementioned tokens:

```
$gplusPersonVo = $gplus->getUserDetails($accessToken, $refreshToken);
```

If the call succeeds you will receive a `GplusPersonVo` which holds all basic profile data:

```
$gplusPersonVo->getAccessToken();
$gplusPersonVo->getDisplayName();
$gplusPersonVo->getEmailAccount();
$gplusPersonVo->getEmails();
$gplusPersonVo->getGender();
$gplusPersonVo->getId();
$gplusPersonVo->getLanguage();
$gplusPersonVo->getRefreshToken();
$gplusPersonVo->getUrlImage();
$gplusPersonVo->getUrlImageBySize($squareSizePixel = 50);
$gplusPersonVo->getUrlProfile();
$gplusPersonVo->getVerified();
$gplusPersonVo->isNewAccessToken();
$gplusPersonVo->isVerified();
```

There is still a bunch of data left which can be accessed as array via `$gplusPersonVo->getRawData()`. If the `accessToken` is not valid anymore the method will automatically try to renew it by the help of the `refreshToken`. In case of failure you will receive a `GplusException`.

### 3.4. Refresh AccessToken manually

[](#34-refresh-accesstoken-manually)

In order to receive a fresh `accessToken` you should call the following method. If the call succeeds you will receive `GplusRefreshAccessTokenVo` which holds among other things a fresh accessToken - `$gplusRefreshAccessTokenVo->getAccessToken()`.

```
$gplusRefreshAccessTokenVo = $gplus->refreshAccessToken($refreshToken);
```

In case of a unsuccessful call you will either receive `FALSE` or an `GplusException`.

---

4. Full example
---------------

[](#4-full-example)

Following a full length example of the above described process flow:

```
// set credentials
$authVo = (new \Simplon\Gplus\Vo\GplusAuthVo())
    ->setClientId(CLIENT_ID)
    ->setClientSecret(CLIENT_SECRET)
    ->setUrlRedirect(AUTH_URL_REDIRECT);

// create instance
$gplus = new \Simplon\Gplus\Gplus($authVo);

// set permission scopes
$scopes = [
    \Simplon\Gplus\GplusConstants::AUTH_SCOPE_EMAIL,
    \Simplon\Gplus\GplusConstants::AUTH_SCOPE_PROFILE,
];

// get auth url
$urlAuth = $gplus->getAuthUrl($scopes);

// --> redirect user to Google's authentication page

// ##############################################

// requestAccessToken($_GET['code']);

    if($gplusRequestAccessTokenVo !== FALSE)
    {
        // --> save accessToken + refreshToken for offline access to DB ...

        // fetch profile data
        $gplusPersonVo = $gplus->getUserDetails(
            $gplusRequestAccessTokenVo->getAccessToken(),
            $gplusRequestAccessTokenVo->getRefreshToken()
        );

        // print data
        var_dump($gplusPersonVo);
    }
}
```

License
=======

[](#license)

Cirrus is freely distributable under the terms of the MIT license.

Copyright (c) 2014 Tino Ehrich ()

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

[![Bitdeli Badge](https://camo.githubusercontent.com/29d4c37461e15746b3cefb11964a3a1ba351c6549bba01488b3778318bcfe22d/68747470733a2f2f64327765637a68766c38323376302e636c6f756466726f6e742e6e65742f666967687462756c632f73696d706c6f6e5f67706c75732f7472656e642e706e67)](https://bitdeli.com/free "Bitdeli Badge")

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

5

Last Release

4463d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3ac00878c8c7a883b6b5cbd697b82838cad15e294e5a52d8c4a173bd664d6b4d?d=identicon)[fightbulc](/maintainers/fightbulc)

---

Top Contributors

[![bitdeli-chef](https://avatars.githubusercontent.com/u/3092978?v=4)](https://github.com/bitdeli-chef "bitdeli-chef (1 commits)")

---

Tags

httpapigoogle plus

### Embed Badge

![Health badge](/badges/simplon-gplus/health.svg)

```
[![Health](https://phpackages.com/badges/simplon-gplus/health.svg)](https://phpackages.com/packages/simplon-gplus)
```

###  Alternatives

[nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

1.8k17.2M267](/packages/nategood-httpful)[bigcommerce/api

Enables PHP applications to communicate with the Bigcommerce API.

1501.1M8](/packages/bigcommerce-api)[quickbooks/payments-sdk

The Official PHP SDK for QuickBooks Online Payments API

2758.2k2](/packages/quickbooks-payments-sdk)[jsor/hal-client

A lightweight client for consuming and manipulating Hypertext Application Language (HAL) resources.

2425.9k1](/packages/jsor-hal-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
