Service Account
carlotta11 opened this issue · 4 comments
Im using a ServiceAccount with a json file. I do not need to authenticate with Google via OAuth 2. Is it possible to include only the class instead of all? Like this:
$client = new Google_Client();
$client->setApplicationName("...");
$client->setScopes(array('https://www.googleapis.com/auth/contacts', 'https://www.googleapis.com/auth/contacts.readonly'));
if ($credentials_file = checkServiceAccountCredentialsFile()) {
$client->setAuthConfig($credentials_file);
} elseif (getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
$client->useApplicationDefaultCredentials();
} else {
echo missingServiceAccountDetailsWarning();
return;
}
$people_service = new Google_Service_PeopleService($client);
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
Hi @carlotta11 do you have any solutions for this??
Hi,
Did anyone find the solution with a service account?
Well, in the end I did it without this class.
Just like I wrote above one year before and it worked and works still ;-)
I have same kind of autorization and i use this code to add a contacto and it finish whitout errors but i dont find the contact in contacts.google.com Do you know why could it be?
$client = new \Google_Client();
$client->setAuthConfig('/.../XXX.json');
// $client->setScopes(['https://www.googleapis.com/auth/contacts']);
//$client->addScope(\Google_Service_PeopleService::CONTACTS);
$client->setScopes(
array(
\Google_Service_PeopleService::CONTACTS,
\Google_Service_PeopleService::CONTACTS_READONLY,
\Google_Service_PeopleService::USERINFO_PROFILE,
\Google_Service_PeopleService::USERINFO_EMAIL,
)
);
$people_service = new \Google_Service_PeopleService($client);
$person = new \Google_Service_PeopleService_Person();
$email1 = new \Google_Service_PeopleService_EmailAddress();
$email1->setValue('xx@xx.com');
$person->setEmailAddresses($email1);
$name = new \Google_Service_PeopleService_Name();
$name->setGivenName('haruki2');
$name->setFamilyName('murakami2');
$person->setNames($name);
$phone1 = new \Google_Service_PeopleService_PhoneNumber();
$phone1->setValue('5491141653254');
$phone1->setType('mobile');
$person->setPhoneNumbers($phone1);
$people_service->people->createContact($person)->execute;
//dd($people_service);
$service = $people_service;
// Print the names for up to 10 connections.
$optParams = array(
'pageSize' => 10,
'personFields' => 'names,emailAddresses',
);
$results = $service->people_connections->listPeopleConnections('people/me', $optParams);
if (count($results->getConnections()) == 0) {
print "No connections found.\n";
} else {
print "People:\n";
foreach ($results->getConnections() as $person) {
if (count($person->getNames()) == 0) {
print "No names found for this connection\n";
} else {
$names = $person->getNames();
$name = $names[0];
printf("%s\n", $name->getDisplayName());
}
}
}