Add photo to new contact
futur22de opened this issue · 1 comments
futur22de commented
Hello,
I'm trying to add a photo to a new contact. That's my try:
function createContact(string $givenName, string $familyName, string $nickName) {
$contact = new Contact($this->people);
$contact->names[0] = new stdClass;
$contact->names[0]->givenName = $givenName;
$contact->names[0]->familyName = $familyName;
$contact->nicknames[0] = new stdClass;
$contact->nicknames[0]->value = $nickName;
$contact->phoneNumbers[0] = new stdClass;
$contact->phoneNumbers[0]->value = '0123456789';
$contact->photos[0] = new stdClass;
$contact->photos[0]->url = 'my private url';
$contact->photos[0]->default = true; // I tried also false
// no error, no photo
$contact->save();
}
I have a new contact in Google Contacts but I can't see a photo. What I have to do? I'm looking forward for your advice. Thanks.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
NazgulTuga commented
I created this code, based in the function "save", from the class "GooglePeople".
public function savePhoto($resourceName,$photoBytes) {
$requestObj = new \stdClass();
//If resource name exists, update the contact.
$method = 'PATCH';
$url = self::PEOPLE_BASE_URL.$resourceName.':updateContactPhoto';
$requestObj = ['photoBytes'=>$photoBytes];
$requestBody = json_encode($requestObj);
$response = $this->googleOAuth2Handler->performRequest($method, $url, $requestBody);
$body = (string) $response->getBody();
if ($response->getStatusCode()!=200) {
throw new Exception($body);
}
$responseObj = json_decode($body);
return $responseObj;
#return $this->convertResponseConnectionToContact($responseObj);
}`