Giter Club home page Giter Club logo

php-google-contacts-v3-api's Introduction

PHP Google Contacts v3 API

Packagist

PHP library for the Google Contacts API (v3)

💡 NOTE: If you're starting a new project, we strongly recommend using our PHP Google People API package instead. It is more capable than this package and uses a newer API which will probably be supported for longer.

Installation & Dependencies

This package and its dependencies can be installed using composer.

Just run composer require rapidwebltd/php-google-contacts-v3-api.

Setup

  1. Install required dependencies. See the 'Dependencies' section above.
  2. Copy or rename .config_blank.json to .config.json. Note the dot (.) at the beginning of the file name.
  3. Fill in the clientID, clientSecret and redirectUri in .config.json.
  • Note that redirectUri should be configure to point towards the redirect-handler.php file.
  • The clientID and clientSecret can be found in the Google Developers console at https://console.developers.google.com/ under 'APIs & auth' -> 'Credentials', after enabling the Contacts API.
  1. Go to authorise-application.php in a web browser. This should give you a URL to authorise your application for Google Contacts.
  2. Go to the authorisation URL provided by the previous step.
  3. Accept the permissions requested on the page displayed. You should then be redirected back to the redirect-handler.php file.
  4. The page generated by the redirect-handler.php file should then present you with a refresh token. Copy this into your .config.json.
  5. Setup is done!

Usage

After the library has been installed and the setup and account association steps have been completed, you can make use of the library.

If your framework does not do this for you, remember to include the require the vendor/autoload.php file on any pages you wish to make use of this library on.

Retrieving Google Contacts

The following code will retrieve all contacts from the associated Google account.

$contacts = rapidweb\googlecontacts\factories\ContactFactory::getAll();

var_dump($contacts);

The ContactFactory::getAll() method will return an array of Contact objects. The contact's details will be available as public member variables of these objects.

The selfURL contained within each Contact object is the unique reference to this particular contact. If you need to retrieve a specific contact in the future, you will need to store this selfURL.

To retrieve a specific contact (by its selfURL), use the following code.

$selfURL = "...";

$contact = rapidweb\googlecontacts\factories\ContactFactory::getBySelfURL($selfURL);

var_dump($contact);

This ContactFactory::getBySelfURL method will return a single Contact object.

Google Contact properties are accessed as follows.

$selfURL = "...";

$contact = rapidweb\googlecontacts\factories\ContactFactory::getBySelfURL($selfURL);

echo $contact->name;
echo $contact->phoneNumber;
echo $contact->email;
echo $contact->content;

Updating existing Google Contacts

The updating of Google Contacts using this library is done in a very object orientated manner.

You must first retrieve a Contact object using one of the methods mentioned previously. You can then modify the contact object's public member variables. To save these changes back to the Google Contacts service, you then pass the modified object to the ContactFactory::submitUpdates($contact) method.

The following code demonstrates in full retrieving a contact, modifying it and submitting the updates.

$selfURL = "...";

$contact = rapidweb\googlecontacts\factories\ContactFactory::getBySelfURL($selfURL);

var_dump($contact);

$contact->name = 'Test';
$contact->phoneNumber = '07812363789';
$contact->email = '[email protected]';
$contact->content = 'Note for example';

$contactAfterUpdate = rapidweb\googlecontacts\factories\ContactFactory::submitUpdates($contact);

var_dump($contactAfterUpdate);

Creating new Google Contacts

Creating a new Google Contact is very easy. Simply call the ContactFactory::create($name, $phoneNumber, $emailAddress) method, passing through appropriate parameters. This method will return the created contact as a Contact object including its newly assigned selfURL.

$name = "Frodo Baggins";
$phoneNumber = "06439111222";
$emailAddress = "[email protected]";
$note = "Note for example";

$newContact = rapidweb\googlecontacts\factories\ContactFactory::create($name, $phoneNumber, $emailAddress, $note);

Config file override

Each method has optional argument for config file override. It is useful when you want to use work with multiple Google accounts at the same time.

$customConfig = (object) array(
    'clientID' => '<clientId which you get according to setup above>',
    'clientSecret' => '<clientSecret which you get according to setup above>',
    'redirectUri' => '<your redirect uri>',
    'developerKey' => '<developer key>',
    'refreshToken' => '<refresh token specific for google account>'
);

$contacts = ContactFactory::getAll($customConfig);

You have to define all variables as the original config is completely ignored. To be more precise, it doesn't have to exist at all.

Examples

Take a look at the following files for basic examples of how to retrieve contacts. They can also be used to ensure you have currently associated your Google account with the library.

  • test.php
  • test_individual.php

php-google-contacts-v3-api's People

Contributors

divineomega avatar lucascdsilva avatar mgi1982 avatar resand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-google-contacts-v3-api's Issues

Fatal error: Class 'Google_Http_Request' not found

I encounter this error:
Fatal error: Class 'Google_Http_Request' not found in /factories/ContactFactory.php on line
$req = new \Google_Http_Request('https://www.google.com/m8/feeds/contacts/default/full?max-results=10000&updated-min=2007-03-16T00:00:00');

I installed manually the script, downloaded the code as a zip and extract it into my host.
I'm using the latest version of https://github.com/google/google-api-php-client
Please,Can you guide me to find out what is causing this error?Seems is missing some library/dependencies?
Thank you!

Showing Fatal error: Uncaught exception 'Google_IO_Exception' with message '<url> malformed'

I get following error if I open "test_individual.php" in web browser-

Fatal error: Uncaught exception 'Google_IO_Exception' with message ' malformed' in /home/cityretails/public_html/testing/3/vendor/google/apiclient/src/Google/IO/Curl.php:126 Stack trace: #0 /home/cityretails/public_html/testing/3/vendor/google/apiclient/src/Google/IO/Abstract.php(136): Google_IO_Curl->executeRequest(Object(Google_Http_Request)) #1 /home/cityretails/public_html/testing/3/vendor/google/apiclient/src/Google/Auth/OAuth2.php(77): Google_IO_Abstract->makeRequest(Object(Google_Http_Request)) #2 /home/cityretails/public_html/testing/3/factories/ContactFactory.php(79): Google_Auth_OAuth2->authenticatedRequest(Object(Google_Http_Request)) #3 /home/cityretails/public_html/testing/3/test_individual.php(12): rapidweb\googlecontacts\factories\ContactFactory::getBySelfURL('...') #4 {main} thrown in /home/cityretails/public_html/testing/3/vendor/google/apiclient/src/Google/IO/Curl.php on line 126

I don't know whats going wrong there while I have setup everything correctly.

Add/update and delete contact images

Hi. I did see that there was some talk of being able to add images to contacts a while back. Has there been any advancement on this and if so how far along are we? Just wondering because if nothing has been done, I'll take a fork and attempt it myself.

Thanks.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Error 400 authorise-application.php generated link

When I follow the generated link give me that error.

error400

.config.json file:
{ "clientID": "1038blabla05-fekamkh9blablablal2s9r9e2fj9a.apps.googleusercontent.com", "clientSecret": "QA-FiblablablaANYXnIH", "redirectUri": "redirect-handler.php", "developerKey": "", "refreshToken": "" }
I tired in windows 10 with xampp and before into a raspberry pi 3 so i understand that I make some wrong. Thanks.

Does the client support Extended Properties?

From the documentation:

It is possible to set any additional contact- or contact group- related information as an extended property (arbitrary name - value pair) for a contact or contact group entry. Preserving key uniqueness is a responsibility of clients. Value of the extended property may be stored as a value (arbitrary string) or an XML blob (these are mutually exclusive; instead of a valid XML blob plain text can be used). Each contact may have at most ten (10) extended properties associated. Each of them should be reasonably small, that is it should not be a photo, ringtone etc.

See https://developers.google.com/google-apps/contacts/v3/reference?authuser=1#ProjectionsAndExtended


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Duplicated new contacts

When i'm adding new contact i have it doubled in my google contacts.

`$name = $number;
$phoneNumber = "+48".$number;
$emailAddress = $number.'@'.$number.'.com';

if(($newContact = rapidweb\googlecontacts\factories\ContactFactory::create($name, $phoneNumber, $emailAddress...`


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

test.php does not work

Hi , thank you for the great api , but the test.php file does not work , I get this error: Undefined variable: contactsArray in /var/www/html/google-contacts/vendor/rapidwebltd/php-google-contacts-v3-api/factories/ContactFactory.php on line 70,
you know what can be ?


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Logical Error while editing content in contact

Hi thank You very much for the extension.
Please check in rapidweb\googlecontacts\factories\ContactFactory in method submitUpdates - there is no line for editing content of the contact. The xml that we get from google is:
`

<entry xmlns="http://www.w3.org/2005/Atom" mlns:batch="http://schemas.google.com/gdata/batch" mlns:gContact="http://schemas.google.com/contact/2008" xmlns:gd="http://schemas.google.com/g/2005">
	<id>http://www.google.com/m8/feeds/contacts/someaccount/base/f22c9988edd3ec1</id>
	<updated>2017-11-12T16:24:17.414Z</updated> 
	<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact"/>
	<title type="text">Test Buyer (127724)</title>
	<content type="text">Test description</content> 
	<link rel="http://schemas.google.com/contacts/2008/rel#edit-photo" type="image/*" 				href="https://www.google.com/m8/feeds/photos/media/someaccount/f22c9988edd3ec1/1B2M2Y8AsgTpgAmY7PhCfg"/> <link rel="self" type="application/atom+xml" href="https://www.google.com/m8/feeds/contacts/someaccount/full/f22c9988edd3ec1"/> 
	<link rel="edit" type="application/atom+xml" href="https://www.google.com/m8/feeds/contacts/someaccount/full/f22c9988edd3ec1/1510503857414002"/>
	<gd:email rel="http://schemas.google.com/g/2005#work" address="[email protected]"/> 
	<gd:phoneNumber rel="http://schemas.google.com/g/2005#work" uri="tel:+somephone">+somephone</gd:phoneNumber> 

`
And the line of code
$contactGDNodes = $xmlContactsEntry->children('http://schemas.google.com/g/2005');
will return only gd:email and gd:phoneNumber. You made special line for title, but forget about content:
$xmlContactsEntry->title = $updatedContact->name;
Best regards.

Warning: rapidweb\googlecontacts\factories\ContactFactory::submitUpdates(): Cannot assign to an array of nodes (duplicate subnodes or attr detected)

Not sure what I've done wrong
when using test_individual.php?selfURL=http.......
where selfURL is retrieved from one of the contacts in test.php
i get the following error:
Warning: rapidweb\googlecontacts\factories\ContactFactory::submitUpdates(): Cannot assign to an array of nodes (duplicate subnodes or attr detected) in C:\wamp2\www\gcontacts\factories\ContactFactory.php on line 147

It works with only one google account?

Thanks for the work done.
We can use this software you just associating it with a specific Google account , or with all the user accounts that permit on google ?

Thanks in advance.
Sorry for my bad english.

Adding location to a contact

Hi , thank you for this wonderful library!! I want to add location when I create a contact. Is this achievable ?
Do you know the appropriate rel attribute and gd: element that are needed in order to do so?

Thank you in advance.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Does the submitUpdates method allow for a contact object with multiple email addresses?

I have an array of email addresses when I get a contact and I'd like to remove one and then update the contact object. Does the submitUpdates method allow for a contact object with multiple email addresses?

[email] => Array
        (
            [0] => Array
                (
                    [type] => work
                    [email] => [email protected]
                )

            [1] => Array
                (
                    [type] => work
                    [email] => [email protected]
                )

            [2] => Array
                (
                    [type] => 
                    [email] => [email protected]
                )

            [3] => Array
                (
                    [type] => other
                    [email] => [email protected]
                )

        )

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Add 'Quick Start' section to readme

Functionality to cover:

  • Retrieval of all contacts
  • Retrieval of individual contact using self URLs (explanation of self URL)
  • Creation of new contacts
  • Modification to existing contacts

How to obtain all emails and phoneNumbers from Google Contact?

I need to retrieve all emails and phoneNumbers from Google Contacts data. Do we have any plans to allow this? Currently in the ContactFactory.php it scans for email but seems to return only 1... looks like the last one of the Array.

Thanks for helping.!

simplexml_load_string(): Entity: line 7: parser error : Opening and ending tag mismatch: meta line 1 and head

Hello,
I followed the configuration steps and im unable to retrieve the contact list, when i select the google account i have the error:
simplexml_load_string(): Entity: line 7: parser error : Opening and ending tag mismatch: meta line 1 and head
im using laravel 5.5 with php 7.1.
I test the client id and client secret with another library and it work, but i need to create contacts and the other library has not that option, please, helpme to discover what im doing wrong

Delete all contacts

Hello and thank you for your project,
Would it be possible to implement the delete function for all contacts?
That would be very helpful.
Thank you very much.

Does this client support Service Accounts?

From the Google Documentation:

If you have a Google Apps domain—if you use Google Apps for Work, for example—an administrator of the Google Apps domain can authorize an application to access user data on behalf of users in the Google Apps domain. For example, an application that uses the Google Calendar API to add events to the calendars of all users in a Google Apps domain would use a service account to access the Google Calendar API on behalf of users. Authorizing a service account to access data on behalf of users in a domain is sometimes referred to as "delegating domain-wide authority" to a service account.

See https://developers.google.com/api-client-library/php/auth/service-accounts

Installation with composer

When runing composer update with the following code:

{
  "require": {
       "rapidwebltd/php-google-contacts-v3-api": "1.*"
   }
}

I just see the files of the google api
Am I doing something wrong?
Is there a directory structure I should follow?

Overlap contacts of the same type

So I understand the code, does not allow pulling contacts with the same type, since it uses the contact type as array key.

Ex:

Type Number
cell 99999999
cell 88888888
   //result only 
   array('cell' => 88888888);

Fatal error: Uncaught exception 'Google_Auth_Exception'

I installed the script with composer( composer require rapidwebltd/php-google-contacts-v3-api ) in the directory "google_contacts".After the google send the auth code and redirects me to the "redirect-handler.php" I receive this message.

Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error fetching OAuth2 access token, message: 'invalid_client'' in /google_contacts/vendor/google/apiclient/src/Google/Auth/OAuth2.php:126 Stack trace: #0 /google_contacts/vendor/google/apiclient/src/Google/Client.php(128): Google_Auth_OAuth2->authenticate('4/98FDtobndj_Yx...', false) #1 /google_contacts/vendor/rapidwebltd/php-google-contacts-v3-api/helpers/GoogleHelper.php(76): Google_Client->authenticate('4/98FDtobndj_Yx...') #2 /google_contacts/vendor/rapidwebltd/php-google-contacts-v3-api/redirect-handler.php(19): rapidweb\googlecontacts\helpers\GoogleHelper::authenticate(Object(Google_Client), '4/98FDtobndj_Yx...') #3 {main} thrown in /google_contacts/vendor/google/apiclient/src/Google/Auth/OAuth2.php on line 126

authorization link crashed

after i get the link after opening authorise-application.php in the browser ,i tried to authorize the app but the link won't open ,the link redirected me to a crashed site

Problem with device synchronization

I'm going through a problem that I have not seen people commenting too much, the synchronization of GoogleContact contacts with the mobile, I'm trying the problem with at least 5 devices that I've tested and found no solution, does anyone know in any way?
I'm able to insert contacts perfectly through php-google-contacts-v3-api but they are not going to the devices.
I have already tried to force an update of the devices and even back up the factory settings thought it might be something in the settings.
When I returned the factory settings, the first update he pulled came all contacts, but after that he did not pull anything.
Is someone having the same problem or does it help me in how to solve the problem?

Full rewrite to use Google People API

This is proposal to fully rewrite this library to use the Google People API instead of the Google Contacts v3 API. A decision would also need to be whether the GitHub repo and Packagist package should be renamed, as the current name would no longer be accurate.

Reasoning

Although the currently used Google Contacts v3 API is still functional and used, the documentation states the following which suggests it may be deprecated.

For read and write access to users' contacts, use the People API, which provides both contact and profile information using JSON instead of the older GData protocol.

The Google People API appears to offer the same functionality as Google Contacts v3 API, but via a more simply JSON API.

composer required?

Hi,

sorry i am new to php.
I am not hosting on my own (buh... i know), and use a hosting service with a contact form.
Out of that, i want to create a Google contact with the data provided from the form.

However, i am not allowed to install composer on my hosting service (1blu).
Is there any workaround?


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Can't access many attributes !

i want to access some attributes in the api but i can't do this
the create method can only set the name, email,phonenumber and notes, i want to set many other variables EXP: ['organization']['orgName'], i'll try to do this with my instance of the repo but i want to check if there is any tries have made before with this task ,and is it doable or not ?

Add multiple phone types, phone numbers

Hi there,

I'm using your API to sync Google contacts in my app. However, I need to add multiple phone type, phone number to a contact. Could you extent this library to support this. Thank you!

Example:
Wife: +1988519007
Husband:+1988519234


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Can't set the prefix name for Contact

when i add new contact i set the name attr with some string and the api explodes the name into first, middle and last name.
i want to set the prefix and first name while inserting the name into my account

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.