rapidwebltd/php-google-people-api

Problem adding new Contact

Defiant74 opened this issue · 3 comments

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! We accept bounties via Bountysource.

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.

can you share full script how to create new contact


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();