Giter Club home page Giter Club logo

Comments (5)

kuriban avatar kuriban commented on June 7, 2024

Hi. I change function create. So you can create multiple phone type and multiple email
$phoneNumber, $emailAddress - must be arrays

 public static function create($name, $phoneNumber, $emailAddress)
    {
        $doc = new \DOMDocument();
        $doc->formatOutput = true;
        $entry = $doc->createElement('atom:entry');
        $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:atom', 'http://www.w3.org/2005/Atom');
        $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gd', 'http://schemas.google.com/g/2005');
        $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gd', 'http://schemas.google.com/g/2005');
        $doc->appendChild($entry);

        $title = $doc->createElement('title', $name);
        $entry->appendChild($title);

        foreach($emailAddress as $key=>$one_mail){
            $email = $doc->createElement('gd:email');
            if(!$key){
                $email->setAttribute('primary', 'true');
            }
            $email->setAttribute('rel','http://schemas.google.com/g/2005#work');
            $email->setAttribute('address',$one_mail);
            $entry->appendChild($email);
        }

        foreach($phoneNumber as $key=>$phone){
            $contact = $doc->createElement('gd:phoneNumber', $phone);
            if(!$key){
                $contact->setAttribute('primary', 'true');
            }
            $contact->setAttribute('rel', 'http://schemas.google.com/g/2005#work');
            $entry->appendChild($contact);
        }

        $xmlToSend = $doc->saveXML();

        $client = GoogleHelper::getClient();

        $req = new \Google_Http_Request('https://www.google.com/m8/feeds/contacts/default/full');
        $req->setRequestHeaders(array('content-type' => 'application/atom+xml; charset=UTF-8; type=feed'));
        $req->setRequestMethod('POST');
        $req->setPostBody($xmlToSend);

        $val = $client->getAuth()->authenticatedRequest($req);

        $response = $val->getResponseBody();

        $xmlContact = simplexml_load_string($response);
        $xmlContact->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');

        $xmlContactsEntry = $xmlContact;

        $contactDetails = array();

        $contactDetails['id'] = (string) $xmlContactsEntry->id;
        $contactDetails['name'] = (string) $xmlContactsEntry->title;

        foreach ($xmlContactsEntry->children() as $key => $value) {
            $attributes = $value->attributes();

            if ($key == 'link') {
                if ($attributes['rel'] == 'edit') {
                    $contactDetails['editURL'] = (string) $attributes['href'];
                } elseif ($attributes['rel'] == 'self') {
                    $contactDetails['selfURL'] = (string) $attributes['href'];
                }
            }
        }

        $contactGDNodes = $xmlContactsEntry->children('http://schemas.google.com/g/2005');

        foreach ($contactGDNodes as $key => $value) {
            $attributes = $value->attributes();

            if ($key == 'email') {
                $contactDetails[$key] = (string) $attributes['address'];
            } else {
                $contactDetails[$key] = (string) $value;
            }
        }

        return new Contact($contactDetails);
    } 

from php-google-contacts-v3-api.

DivineOmega avatar DivineOmega commented on June 7, 2024

It looks like we'll be able to change http://schemas.google.com/g/2005#work to http://schemas.google.com/g/2005#home or http://schemas.google.com/g/2005#other in order to submit multiple different types of phone numbers or email addresses.

from php-google-contacts-v3-api.

kuriban avatar kuriban commented on June 7, 2024

Ok. Can you solve a problem with update multiple count?

from php-google-contacts-v3-api.

brianyoungblood avatar brianyoungblood commented on June 7, 2024

I have a similar question related to this. Is there a possible solution for updating multiple emails? ie. #45

from php-google-contacts-v3-api.

DivineOmega avatar DivineOmega commented on June 7, 2024

Unfortunately, this library can't handle multiple email addresses, telephone numbers, etc.

We've recently written a new package, PHP Google People API, that uses an improved API to access Google Contacts information. This library is very capable of retrieving and updating multiple emails address, telephone numbers and so on.

from php-google-contacts-v3-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.