rapidwebltd / php-google-people-api

👥 This package provides a user friendly way of interacting with Google Contacts via the Google People API.
GNU Lesser General Public License v3.0
100 stars 39 forks source link

Problem adding new Contact #14

Open Defiant74 opened 5 years ago

Defiant74 commented 5 years ago

Hello!

I wrote a script where Retrieving and Updating Contacts is working perfect. The only thing I'm not able to do, is adding a new contact.

I am using it this way as shown in your documentation: // Create new contact $contact = new Contact($people); $contact->names[0] = new stdClass; $contact->names[0]->givenName = 'Testy'; $contact->names[0]->familyName = 'McTest Test'; $contact->save();

The error message is always the following:

Fatal error: Uncaught Error: Class 'Contact' not found in /var/www/html/googlecontacts/google-contacts.php:34 Stack trace: #0 {main} thrown in /var/www/html/googlecontacts/google-contacts.php on line 34

I have added the script.

Thank you very much for your help! Arno.

google-contacts.txt

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/68792756-problem-adding-new-contact?utm_campaign=plugin&utm_content=tracker%2F87779827&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F87779827&utm_medium=issues&utm_source=github).
Defiant74 commented 5 years ago

Hello!

I found the solution.

I forgot to add use RapidWeb\GooglePeopleAPI\Contact

So I need to have these four lines in my script so that everything works. Maybe you want to add that to your documentation:

require_once DIR . '/vendor/autoload.php'; use RapidWeb\GooglePeopleAPI\GooglePeople; use RapidWeb\GoogleOAuth2Handler\GoogleOAuth2Handler; use RapidWeb\GooglePeopleAPI\Contact;

Best regards, Arno.

ashokchandra2988 commented 2 years ago

can you share full script how to create new contact

zilvinasklp commented 11 months ago


require_once './vendor/autoload.php';

use RapidWeb\GoogleOAuth2Handler\GoogleOAuth2Handler;
use RapidWeb\GooglePeopleAPI\GooglePeople;
use RapidWeb\GooglePeopleAPI\Contact;

$clientId     = 'XX';
$clientSecret = 'XX';
$refreshToken = 'XX';
$scopes       = ['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/contacts', 'https://www.googleapis.com/auth/contacts.readonly'];

$googleOAuth2Handler = new GoogleOAuth2Handler($clientId, $clientSecret, $scopes, $refreshToken);

$people = new GooglePeople($googleOAuth2Handler);
$contact = new Contact($people);
$contact->names[0] = new stdClass;
$contact->names[0]->givenName = 'Testy 2';
$contact->names[0]->familyName = 'McTest Test 2';
$contact->save();