Download the PHP package yidas/google-apiclient-helper without Composer
On this page you can find all versions of the php package yidas/google-apiclient-helper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yidas/google-apiclient-helper
More information about yidas/google-apiclient-helper
Files in yidas/google-apiclient-helper
Package google-apiclient-helper
Short Description Google APIs Client Helper - Easy way to accessing Google APIs with PHP
License MIT
Homepage https://github.com/yidas/php-google-api-client-helper
Informations about the package google-apiclient-helper
Google API Client Helper
Google APIs Client Helper - Easy way to accessing Google APIs with PHP
FEATURES
-
Easy way to develop and manage Google API application
-
Documentation supported for Service SDK
- Simple usage for each Service
This Helper is based on google-api-php-client and google-api-php-client-services.
OUTLINE
- Demonstration
- Requirements
- Installation
- Google Client
- Configuration
- Config Array Method
- Config Chain Method
- Encapsulating Method
- AccessToken Usage
- refreshAccessToken()
- verifyAccessToken()
- verifyScopes()
- Implementation
- Configuration
- Google Services
- People
- Attributes
- getSimpleContacts()
- createContact()
- updateContact()
- deleteContact()
- People
- Exceptions
-
Reference
DEMONSTRATION
REQUIREMENTS
This library requires the following:
- PHP 5.4.0+
- google/apiclient 2.0+
INSTALLATION
Run Composer in your project:
composer require yidas/google-apiclient-helper
Then you could call it after Composer is loaded depended on your PHP framework:
GOOGLE CLIENT
Configuration
There are many way to set Google_Client
by Helper:
Config Array Method
The config keys refer to the methods of Google_Client
. For exmaple, authConfig
refers to Google_Client->setAuthConfig()
.
Config Chain Method
The methods refer to the same method names of Google_Client
. For exmaple, setAuthConfig()
refers to Google_Client->setAuthConfig()
.
`
Encapsulating Method
After encapsulating Google_Client into Helper, the Helper would share with the same Google_Client object.
AccessToken Usage
refreshAccessToken()
Simple way to get refreshed access token or false expired to skip
Example:
Helper handles the setting
setAccessType('offline')
&setApprovalPrompt('force')
for refresh token.
verifyAccessToken()
Verify an access_token. This method will verify the current access_token by Google API, if one isn't provided.
verifyScopes()
Verify scopes of tokenInfo by access_token. This method will verify the current access_token by Google API, if one isn't provided.
Example:
Implementation
There are more implementations such as addScope()
or createAuthUrl()
for OAuth register, you cloud refer following sample code:
GOOGLE SERVICES
You could directly use any Service Helpers which uses Google_Client
from yidas\google\apiHelper\Client
:
Or you could reset a Google_Client
for each Service Helper:
Use getService()
to get back current Google Service object for advanced usage:
People
API Document: https://developers.google.com/people/api/rest/
People helper has smart call refered to Google_Service_PeopleService_Person methods, which provides easy interface to setValue()
for a person.
Attributes
It's easy to set attributes for a person by Helper, which provides three types for input data:
1. Origin Object
Input by original Google Attribute Classes that are not so convenience.
2. Array
Input by array type would map to the API key-value setting.
3. String
Input by string type would enable Helper attribute handler which automatically settles value for all attributes.
getSimpleContacts()
Get simple contact data with parser
Example:
Result:
This is simple fields parser, you could use
listPeopleConnections()
if you need all fields.
createContact()
Create a People Contact
Example:
Resource Name:
$person->resourceName
or$person['resourceName']
.
updateContact()
Update a People Contact
Example:
deleteContact
Delete a People Contact
Example:
You could also use find pattern:
EXCEPTIONS
For all Google Exception including Client and Services:
Otherwise, for Google Services only: