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

Service Account #3

Open
carlotta11 opened this issue Apr 3, 2018 · 4 comments
Open

Service Account #3

carlotta11 opened this issue Apr 3, 2018 · 4 comments

Comments

@carlotta11
Copy link

carlotta11 commented Apr 3, 2018

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.

@Julian-B90
Copy link

Hi @carlotta11 do you have any solutions for this??

@bhagchandani
Copy link

Hi,
Did anyone find the solution with a service account?

@carlotta11
Copy link
Author

Well, in the end I did it without this class.
Just like I wrote above one year before and it worked and works still ;-)

@Lucho1976
Copy link

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

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

4 participants