Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem adding new Contact #14

Open
Defiant74 opened this issue Jan 16, 2019 · 3 comments
Open

Problem adding new Contact #14

Defiant74 opened this issue Jan 16, 2019 · 3 comments

Comments

@Defiant74
Copy link

Defiant74 commented Jan 16, 2019

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.

@Defiant74
Copy link
Author

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
Copy link

can you share full script how to create new contact

@zilvinasklp
Copy link

zilvinasklp commented Dec 4, 2023


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants