Skip to content

Class GContacts

Stefan Kientzler edited this page Apr 26, 2023 · 7 revisions

Full name:     \SKien\Google\GContacts


Class to manage the contacts of a google account.

This class encapsulates the following Google People API resources:

  • people
  • people.connections

If one of the methods that calls the google API fails (if it returns false), the last responsecode and furter informations can be retrieved through following methods of the GClient instance this object was created with:

  • $oClient->getLastResponseCode()
  • $oClient->getLastError()
  • $oClient->getLastStatus()

See Also:

Constants

Constant Description
CONTACTS full access to the users contacts
CONTACTS_READONLY readonly access to the users contacts
CONTACTS_OTHER_READONLY readonly access to the users other contacts
SO_LAST_MODIFIED_ASCENDING Sort people by when they were changed; older entries first.
SO_LAST_MODIFIED_DESCENDING Sort people by when they were changed; newer entries first.
SO_FIRST_NAME_ASCENDING Sort people by first name.
SO_LAST_NAME_ASCENDING Sort people by last name.
DEF_DETAIL_PERSON_FIELDS the default personFields for detail view
DEF_LIST_PERSON_FIELDS the default personFields for detail view

Overview

Method Description
__construct Create instance an pass the clinet for the requests.
addPersonFields Add personFields/readMask for next request.
createContact Creates a new contact.
deleteContact Delete the requested contact.
deleteContactPhoto Delete contact photo for given contact.
getContact Get the contact specified by its resourceName.
list Get the whole contact list.
search Search within the contacts.
setContactPhoto Set contact photo from base64 encoded image data.
setContactPhotoFile Set contact photo from image file.
setContactStarred Set or unset the 'starred' mark for the specified contact.
setPageSize Set the pagesize for reading lists.
updateContact Updates an existing contact specified by resourceName.

Methods

__construct

Create instance an pass the clinet for the requests.

public GContacts::__construct(\SKien\Google\GClient $oClient)

Parameters:

Parameter Type Description
oClient \SKien\Google\GClient

[go to top]


addPersonFields

Add personFields/readMask for next request.

public GContacts::addPersonFields(mixed $fields) : void

Can be called multiple and/or by passing an array of personFields. All const GContact::PF_xxxx can be specified. If no personFields specified before an API call, as default setting

  • self::DEF_DETAIL_PERSON_FIELDS for the getContact() and
  • self::DEF_LIST_PERSON_FIELDS for the list() and search() call is used

Parameters:

Parameter Type Description
fields mixed

[go to top]


createContact

Creates a new contact.

public GContacts::createContact(\SKien\Google\GContact $oContact) : \SKien\Google\GContact|false

Parameters:

Parameter Type Description
oContact \SKien\Google\GContact

Return Type: \SKien\Google\GContact|false

See Also:

[go to top]


deleteContact

Delete the requested contact.

public GContacts::deleteContact(string $strResourceName) : bool

Parameters:

Parameter Type Description
strResourceName string

Return Type: bool

See Also:

[go to top]


deleteContactPhoto

Delete contact photo for given contact.

public GContacts::deleteContactPhoto(string $strResourceName) : bool

Parameters:

Parameter Type Description
strResourceName string

Return Type: bool

See Also:

[go to top]


getContact

Get the contact specified by its resourceName.

public GContacts::getContact(string $strResourceName) : \SKien\Google\GContact|false

Note that only the person fields specified with addPersonFields() are included in the result.

Parameters:

Parameter Type Description
strResourceName string

Return Type: \SKien\Google\GContact|false

See Also:

[go to top]


list

Get the whole contact list.

public GContacts::list(string $strSortOrder = self::SO_LAST_NAME_ASCENDING, string $strGroupResourceName = '') : array|false

Parameters:

Parameter Type Description
strSortOrder string one of the self::SO_xxx constants
strGroupResourceName string

Return Type: array|false

See Also:

[go to top]


search

Search within the contacts.

public GContacts::search(string $strQuery) : array|false

The query matches on a contact's names, nickNames, emailAddresses, phoneNumbers, and organizations fields. The search for phone numbers only works, if leading '+' and contained '(', ')' or spaces are omitted in the query! The query is used to match prefix phrases of the fields on a person. For example, a person with name "foo name" matches queries such as "f", "fo", "foo", "foo n", "nam", etc., but not "oo n".

Note: The count of contacts, the search request returns is limitetd to the pageSize (which is limited itself to max. 30 at all). If there are more contacts in the list that matches the query, unfortunately NO further information about that additional contacts - and how many - are available!

Parameters:

Parameter Type Description
strQuery string the query to search for

Return Type: array|false

See Also:

[go to top]


setContactPhoto

Set contact photo from base64 encoded image data.

public GContacts::setContactPhoto(string $strResourceName, string $blobPhoto) : bool

Parameters:

Parameter Type Description
strResourceName string
blobPhoto string base64 encoded image

Return Type: bool

See Also:

[go to top]


setContactPhotoFile

Set contact photo from image file.

public GContacts::setContactPhotoFile(string $strResourceName, string $strFilename) : bool

Supported types are JPG, PNG, GIF and BMP.

Parameters:

Parameter Type Description
strResourceName string
strFilename string

Return Type: bool

See Also:

[go to top]


setContactStarred

Set or unset the 'starred' mark for the specified contact.

public GContacts::setContactStarred(string $strResourceName, bool $bSetStarred = true) : bool

The 'starred' mark just means, the contact belongs to the system group contactGroups/starred.

Parameters:

Parameter Type Description
strResourceName string
bSetStarred bool

Return Type: bool

See Also:

[go to top]


setPageSize

Set the pagesize for reading lists.

public GContacts::setPageSize(int $iPageSize) : void

May be limited to the max. pgaesize for the request.

  • contact list: max. pagesize is 1000
  • search: max. pagesize is 30

Parameters:

Parameter Type Description
iPageSize int

[go to top]


updateContact

Updates an existing contact specified by resourceName.

public GContacts::updateContact(string $strResourceName, \SKien\Google\GContact $oContact) : \SKien\Google\GContact|false

To prevent the user from data loss, this request fails with an 400 response code, if the contact has changed on the server, since it was loaded. Reload the data from the server and make the changes again!

Parameters:

Parameter Type Description
strResourceName string
oContact \SKien\Google\GContact

Return Type: \SKien\Google\GContact|false

See Also:

[go to top]


Clone this wiki locally