Download the PHP package simplon/gplus without Composer
On this page you can find all versions of the php package simplon/gplus. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download simplon/gplus
More information about simplon/gplus
Files in simplon/gplus
Package gplus
Short Description Google+ API Library
License MIT
Homepage https://github.com/fightbulc/simplon_gplus
Informations about the package gplus
_ _ _ ___(_)_ __ ___ _ __ | | ___ _ __ __ _ _ __ | |_ _ ___ / __| | '_ ` _ \| '_ \| |/ _ \| '_ \ / _` | '_ \| | | | / __| \__ \ | | | | | | |_) | | (_) | | | | | (_| | |_) | | |_| \__ \ |___/_|_| |_| |_| .__/|_|\___/|_| |_| \__, | .__/|_|\__,_|___/ |_| |___/|_|
Simplon/Gplus
- Installing
- Setup Gplus module
2.1. Create authentication container
2.2. Create Gplus module instance - Usage
3.1. Request authentication url
3.2. Request AccessToken
3.3. Read user profile data
3.4. Refresh AccessToken manually - Full example
Dependecies
- PHP >= 5.4
- CURL
1. Installing
Install easy via composer:
2. Setup Gplus module
For all calls we wanna make we need to initialise our Gplus module with our . If you happen to miss these credentials hop over to Google's console and create them.
2.1. Create authentication container
We use a value object to hold our credentials. I love value objects because of their clear communication what kind of data they hold.
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 .
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:
2.2. Create Gplus module instance
Alright, now that we have our we can proceed to create our instance.
3. Usage
This scenario shows an authentication flow initialised via the server. If you happen to have already an and you can jump straight to point .
Remember: We need the prior created Gplus instance in order to interact with Google's API.
3.1. Request authentication url
We need an 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.
For this example we will request access to the and his/her . Note: In the following example I use a set of 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.
Now, lets fetch the . This URL should be passed to the web client which redirects the user to Google's authentication process.
3.2. Request AccessToken
When everything went fine Google will redirect to our prior defined with a GET parameter named which is attached to the url. We will use this code now to exchange it for a valid .
If everything went fine we will receive a bunch of data via which is another value object. Actually we are mostly interested in only two variables: and its .
The will give us access to the requested while the will renew the as soon as it ended its life time (2 hours). Therefore, its important to save both tokens and never to lose the .
3.3. Read user profile data
In order to read a user's profile data we need the aforementioned tokens:
If the call succeeds you will receive a which holds all basic profile data:
There is still a bunch of data left which can be accessed as array via . If the is not valid anymore the method will automatically try to renew it by the help of the . In case of failure you will receive a .
3.4. Refresh AccessToken manually
In order to receive a fresh you should call the following method. If the call succeeds you will receive which holds among other things a fresh accessToken - .
In case of a unsuccessful call you will either receive or an .
4. Full example
Following a full length example of the above described process flow:
License
Cirrus is freely distributable under the terms of the MIT license.
Copyright (c) 2014 Tino Ehrich ([email protected])
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.