Fetch Contacts from google - php

I used google api to fetch contacts of google account. The code that I used is http://code.google.com/p/google-api-php-client/source/browse/trunk/examples/contacts/simple.php
But when I run the code by applying my credential, it gives me the contacts but just their name. I want the contacts email address.

I always use this to fetch gmail contacts.
http://contactsimporter.com/address-book-importer-demo.html
Hope you will like this too.
It authenticates the user on our own end, doesn't send user to authenticate to gmail.
Just give it a try.
Here's the download link.
http://svetlozar.net/downloads/import.zip

refer this.
Google Authentication API Library with PHP for User Details
http://www.technew.in/forum_thread_621_Google-Authentication-API-Library-with-PHP-for-User-Details.html

You can find how to fetch emails on this link, the problem was on the example code.
This is part of the code refered in the link.
$req = new \apiHttpRequest("https://www.google.com/m8/feeds/contacts/default/full?max-results=9999");
$val = $client->getIo()->authenticatedRequest($req);
$xml = new \SimpleXMLElement($val->getResponseBody());
$xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
$result = $xml->xpath('//gd:email');
foreach($result as $title)
{
$emails[] = $title->attributes()->address;
}

Related

How to get email address of shared file user (Google Drive api PHP)

I'm trying to get the role and email address of persons whom I shared my google drive file.
//this->drive is object of service_drive
$permissions = $this->drive->permissions->listPermissions($file->id);
foreach ($permissions->getPermissions() as $permission){
echo $permission['emailAddress'];
}
this is returning me null, is there anyway I can know completely about the person or at least email address and his role ?
Yes, you can get info as the email, name or role of the people you share your files with using the Permissions: list endpoint. Try this API can help you to play around with the info you want to retrieve using the fields parameters, which uses partial responses.
Translating the explanation from above to PHP code, this is what you would need to do:
// Build a parameters array
$parameters = array();
// Specify what fields you want
$parameters['fields'] = "permissions(*)";
// Call the endpoint
$permissions = $service->permissions->listPermissions($file->id, $parameters);
// print results
foreach ($permissions->getPermissions() as $permission){
echo $permission['emailAddress'];
}

Get youtube channel ID from website

I have the below code for retrieving views and subscribers from a YouTube channel "?q=dsagov"
$UserID = $_GET['q'];
$data = file_get_contents('http://gdata.youtube.com/feeds/api/users/'. $UserID.'');
$xml = new SimpleXMLElement($data);
$stats_data = (array)$xml->children('yt', true)->statistics->attributes();
$stats_data = $stats_data['#attributes'];
echo 'Views = '.$stats_data['subscriberCount'].'<br />';
echo 'Subscribers = '.$stats_data['totalUploadViews'].'<br />';
I would like to take this one step further and find the YouTube channel ID based on a website address, in this case https://www.gov.uk/government/organisations/driving-standards-agency .
So either REGEX the website find the Channel ID or another method which I am not aware of using YouTube API, I can put the URL of the website and have it find the official channel is this possible?
Thanks in advance.
Just to clarify
For example I would like to enter a URL in query "/?q=gov.uk/government/organisations/driving-standards-agency" what the script would do is find the YouTube Channel ID on the URL and run the API and display the results
I don't think this is possible.
Where would you search for website name ? This could be in user's descriptions, video descriptions, many more places for many users and videos.

Google contacts via API

I want to fetch Google contacts for users and create logs of new and updated contacts via a PHP script. Can someone please guide me on how to proceed?
I have implemented the same kind of service for calendar events using 0Auth2.0, but for contacts I didn't find any API in the Google PHP client libraries.
The problem is in the example, it seems that the json encoder does the mess.
One of the developers wrote how to achive email address on this link
http://pastebin.com/kAYT5Jng
You can see part of the discusion right here
Have you tried this project
https://github.com/rapidwebltd/php-google-contacts-v3-api
Fetching all the contacts :
$contacts = rapidweb\googlecontacts\factories\ContactFactory::getAll();
var_dump($contacts);
create new contact
$name = "Frodo Baggins";
$phoneNumber = "06439111222";
$emailAddress = "frodo#example.com";
$note = "Note for example";
$newContact = rapidweb\googlecontacts\factories\ContactFactory::create($name, $phoneNumber, $emailAddress, $note);

Google Contacts API name and email

This is my first post on this site, so forgive me if I butcher it, but I'll try to be a clear and straight forwards as possible.
I'm trying to use the Google Contacts API to import the name and email address from an authenticated users gmail account. I am getting the email address fine using the generic code supplied by Google itself. I've tried to modify it to grab the contact names as well to no avail. Any help would be greatly appreciated. Below is the code I am currently using.
$xml = new SimpleXMLElement($val->getResponseBody());
$xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
$result = $xml->xpath('//gd:email');
$name_result = $xml->xpath('//title');
foreach ($result as $title) {
echo "<div>".$title->attributes()->address."</div>";
}
foreach ($name_result as $name) {
echo "<div class='contact_alt'>".$name."</div>";
}
OK, so I managed to find the answer elsewhere on this site. Didn't mean to post a question with an answer that already existed here. I really did try to look around first so I didn't do that.
PHP GMAIL Contacts XML Parsing with DOMDocument and cURL
An alternative solution I use is asking the Google API to reply with JSON, rather than XML. Parsing the XML with the gd: namespaces gets tricky. The JSON comes back with contact names and emails and it becomes a matter of using json_decode().
$url = 'https://www.google.com/m8/feeds/contacts/%s/full'
$url .= '&access_token=%s'
$url .= &alt=json;
Just add the &alt=json to the request URL.

Get user details from openid

I'm using lightopenid as the login system for a site and after successful login, I need the user's details like his first name, last name, email and date of birth..
How can I get this information from his openid? Suppose for google, I'm using the authentication url as: https://www.google.com/accounts/o8/id
Then after the validate() method returns 1, I'm redirecting the user to another page in my site. But how can I fetch the details of the user after login ?
FYI, I'm using openid for google, yahoo and aol.
And for facebook, I'm using graph api and for twitter, I'm using twitter oauth. Is there any way of fetching user data with these too? Please suggest.
Just read the manual:
http://code.google.com/p/lightopenid/wiki/GettingMoreInformation
$openid->required = array('namePerson/friendly', 'contact/email');
$openid->optional = array('namePerson/first');
before calling $openid->authUrl()!
Then
$openid->validate();
$userinfo = $openid->getAttributes();
$email = $userinfo['contact/email'];
$firstName = $userinfo['namePerson/first'];
You need to add a parameter to specify that you also want to receive data back from the OpenID request.
I append the following to my OpenID requests to get the email details.
&openid.ns.ax=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0&openid.ax.mode=fetch_request&openid.ax.type.email=http://axschema.org/contact/email&openid.ax.required=email
The first part specifies the namespace being used for the extended data.
The second part specifies that we are making a fetch request for the data.
The third part specifies the schema we are using for the email.
And the final part is specifying that we require the email to be returned.
I have tested this with Google and it works fine. I do not have the other accounts, so have not tested it for those.
OAuth and Facebook Graph API will have there own formats, so I am not sure on those ones.
$openid->identity = 'https://www.google.com/accounts/o8/';
// use the following line to obtain the required details. These are the only details that google mail provides.
$openid->required = array('namePerson/friendly', 'contact/email' , 'contact/country/home', 'namePerson/first', 'pref/language', 'namePerson/last');
header('Location: ' . $openid->authUrl());
Seemingly lightopenid provides a method for that:
$openid->validate();
$userinfo = $openid->getAttributes(); // associative array
It returns either SimpleReg or "Attribute Exchange" data. But only if the user agreed to that, I would hope.

Categories