简体   繁体   中英

Google Api for creating contact with php code

I have created one function in which i am getting error related to Scope

Below is the code:

 $client = getClient();
 $client->addScope(Google_Service_PeopleService::CONTACTS);
 $service = new Google_Service_PeopleService($client);


 $person = new Google_Service_PeopleService_Person();
 $email = new Google_Service_PeopleService_EmailAddress();
 $email->setValue('test@test.com');
 $person->setEmailAddresses($email);
 $name = new Google_Service_PeopleService_Name();
 $name->setDisplayName('User de Test');
 $person->setNames($name);
 $phoneNumber = new Google_Service_People_PhoneNumber();
 $phoneNumber->setType('Home');
 $person->setPhoneNumbers($phoneNumber);
 $exe = $service->people->createContact($person);
 print_r($exe);*

Getting Error As Below:

message: Request had insufficient authentication scopes. errors: [ { message: Request had insufficient authentication scopes., domain: global, reason: forbidden } ], status: PERMISSION_DENIED } }

Not sure what your getClient() function does. But assuming it handles requesting the access token similar to the sample code , you will want to set the scope BEFORE it runs the logic to get the access token. So probably change the getClient() function to take a parameter for the scopes to request, and set the scopes in there before the access token request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM