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

Add photo to new contact #16

Open
futur22de opened this issue May 2, 2019 · 1 comment
Open

Add photo to new contact #16

futur22de opened this issue May 2, 2019 · 1 comment

Comments

@futur22de
Copy link

futur22de commented May 2, 2019

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

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

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

2 participants