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

How can I retrieve contacts using this? #23

Closed
benswinburne opened this issue Dec 22, 2013 · 2 comments
Closed

How can I retrieve contacts using this? #23

benswinburne opened this issue Dec 22, 2013 · 2 comments
Assignees
Labels
🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@benswinburne
Copy link

I have been looking through all of the examples

here https://developers.google.com/api-client-library/php/
and here https://github.com/google/google-api-php-client/tree/master/examples

and the services https://github.com/google/google-api-php-client/tree/master/src/Google/Service

but there doesn't appear to be any services which use the scopes which the api documentation states to use.

This may not be the right place to ask but I'm struggling to find any useful documentation or working tutorials which relate to this.

Cheers

@ianbarber
Copy link
Contributor

Unfortunately the contacts API is one of the older GData ones, while this library is for the newer APIs. You can use the OAuth part of the library to request the scope (https://www.googleapis.com/auth/contacts.readonly), and use the token to make the request, but you'll have to parse the data manually. Zend Framework does have the Zend_Gdata classes that might make reading the results a bit easier!

@kyogaraj
Copy link

Is there any contacts service to get google contacts from gmail and export back to gmail working in google-api-php-client? I could

I don't see any google contact service still, should we gohead and use zend framework?
I'm creating a new entry in a very very weird way as shown below. I alsoi want to do batch creation, or batch update/. I don't know how to work around that. Any help would be appreciated.

function createNewEntry($accesstoken){

$_POST[] = array();
$_POST['fname'] ='the_first_name';
$_POST['lname'] = 'the_last_name'
$_POST['email_id'] = '**@***.edu';
$_POST['phone'] = '888-888-8888';
$_POST['postal'] = '9**42';
$_POST['country'] = 'USA';
$_POST['address'] = '123 st, apt 123, 123city';

// create new entry
$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');
$doc->appendChild($entry);

$cat = $doc->createElement('atom:category');
$cat->setAttribute('scheme', 'http://schemas.google.com/g/2005#kind');
$cat->setAttribute('term', 'http://schemas.google.com/
        /2008#contact');
$entry->appendChild($cat);

// add name element
$name = $doc->createElement('gd:name');
$entry->appendChild($name);
$givenName = $doc->createElement('gd:givenName', $_POST['fname']);
$familyName = $doc->createElement('gd:familyName', $_POST['lname']);
$fullName = $doc->createElement('gd:fullName', $_POST['fname'] . $_POST['lname']);
$name->appendChild($givenName);
$name->appendChild($familyName);
$name->appendChild($fullName);

$content = $doc->createElement('atom:content', 'Notes');
$content->setAttribute('type', 'text');
$entry->appendChild($content);
// add email element
$email = $doc->createElement('gd:email');
$entry->appendChild($email);
$email->setAttribute('address', $_POST['email_id']);
$email->setAttribute('displayName', $_POST['fname']);
$email->setAttribute('primary', 'true');

$email->setAttribute('rel', 'http://schemas.google.com/g/2005#work');

// add im element
$im = $doc->createElement('gd:im');
$entry->appendChild($im);
$im->setAttribute('address', $_POST['email_id']);
$im->setAttribute('protocol', 'http://schemas.google.com/g/2005#GOOGLE_TALK');
$im->setAttribute('primary', 'true');
$im->setAttribute('rel', 'http://schemas.google.com/g/2005#home');
// add phone element
$ph = $doc->createElement('gd:phoneNumber', $_POST['phone']);
$entry->appendChild($ph);
$ph->setAttribute('rel', 'http://schemas.google.com/g/2005#home');

//insert Address
$address = $doc->createElement('gd:structuredPostalAddress');
$address->setAttribute('primary', 'true');
$address->setAttribute('rel', 'http://schemas.google.com/g/2005#work');
$entry->appendChild($address);
$postal = $doc->createElement('gd:postcode', $_POST['postal']);
$country = $doc->createElement('gd:country', $_POST['country']);
$fulladd = $doc->createElement('gd:formattedAddress', $_POST['address']);
$address->appendChild($postal);
$address->appendChild($country);
$address->appendChild($fulladd);

$contact_detail = $doc->saveXML();


$url = 'https://www.google.com/m8/feeds/contacts/default/full?&v=3.0&oauth_token='. $accesstoken;
$curl = curl_init();
print_r("auth url is $url");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 5);
curl_setopt($curl, CURLOPT_POSTFIELDS, $contact_detail);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);

$curlheader[0] = "Content-Type: application/atom+xml";
$curlheader[2] = "Content-length:" . strlen($contact_detail);
$curlheader[1] = "Content-Transfer-Encoding: binary";
curl_setopt($curl, CURLOPT_HTTPHEADER, $curlheader);

$xmlresponse = curl_exec($curl);

echo '<pre>';
print "added liz@gmail.com";
var_dump($xmlresponse);
echo '</pre>';

}

bshaffer pushed a commit to bshaffer/google-api-php-client that referenced this issue Mar 2, 2016
Add CHANGELOG, CONTRIBUTING and COPYING high-level doc to repo

Part of googleapis#23
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

4 participants