Cześć.
Potrzebuję pobrać adresy email z kontaktów.
Udało mi się pobrać kontakty ale niestety dostaje drzewko bez maila (jest imię i nazwisko, id).
Wiecie jak pobrać email kontaktu z konta google przez api?
Oto mój kod który pobiera kontakty:
require_once APPPATH . 'vendor/google/src/Google_Client.php';
require_once APPPATH . 'vendor/google/src/contrib/Google_Oauth2Service.php';
$client = new Google_Client();
$client->setApplicationName("PHP Google Test");
$client->setClientId('xxx');
$client->setClientSecret('xxx');
$client->setRedirectUri('http://www.domain.xx/admin/others/google?test');
$client->setScopes("http://www.google.com/m8/feeds/");
$oauth2 = new Google_Oauth2Service($client);
if (isset($_GET['code'])) { $client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
$redirect = 'http://www.domain.xx/admin/others/google';
header('Location: ' . filter_var
($redirect, FILTER_SANITIZE_URL
)); }
if (isset($_SESSION['token'])) { $client->setAccessToken($_SESSION['token']);
}
if (isset($_REQUEST['logout'])) { unset($_SESSION['token']); $client->revokeToken();
}
if ($client->getAccessToken()) {
$req = new Google_HttpRequest("https://www.google.com/m8/feeds/contacts/default/full");
$val = $client->getIo()->authenticatedRequest($req);
$response = json_encode(simplexml_load_string($val->getResponseBody()));
print "<pre>" . print_r(json_decode
($response, true), true) . "</pre>"; $_SESSION['token'] = $client->getAccessToken();
} else {
$auth = $client->createAuthUrl();
}
$auth = $client->createAuthUrl();
echo '<a href="' . $auth . '" target="_blank">' . $auth . '</a>';
I otrzymuję przykład:
[24] => Array
(
[id] =>
<a href="http://www.google.com/m8/feeds/contacts/xxxx@gmail.com/base/xxx" target="_blank">http://www.google.com/m8/feeds/contacts/xx...il.com/base/xxx
</a> [updated] => 2016-03-13T21:13:40.065Z
[category] => Array
(
[@attributes] => Array
(
[scheme] =>
<a href="http://schemas.google.com/g/2005#kind" target="_blank">http://schemas.google.com/g/2005#kind
</a> [term] =>
<a href="http://schemas.google.com/contact/2008#contact" target="_blank">http://schemas.google.com/contact/2008#contact
</a> )
)
[title] => Array
(
[@attributes] => Array
(
[type] => text
)
)
[link] => Array
(
[0] => Array
(
[@attributes] => Array
(
[rel] =>
<a href="http://schemas.google.com/contacts/2008/rel#edit-photo" target="_blank">http://schemas.google.com/contacts/2008/rel#edit-photo
</a> [type] => image/*
[href] =>
<a href="https://www.google.com/m8/feeds/photos/media/xxxx@gmail.com/xxx/xxxx" target="_blank">https://www.google.com/m8/feeds/photos/medi...il.com/xxx/xxxx
</a> )
)
[1] => Array
(
[@attributes] => Array
(
[rel] => self
[type] => application/atom+xml
[href] =>
<a href="https://www.google.com/m8/feeds/contacts/xxxx@gmail.com/full/xxx" target="_blank">https://www.google.com/m8/feeds/contacts/xx...il.com/full/xxx
</a> )
)
[2] => Array
(
[@attributes] => Array
(
[rel] => edit
[type] => application/atom+xml
[href] =>
<a href="https://www.google.com/m8/feeds/contacts/xxxx@gmail.com/full/xxx/xxxx" target="_blank">https://www.google.com/m8/feeds/contacts/xx...m/full/xxx/xxxx
</a> )
)
)
)
Proszę o pomoc
ktoś pomoże? (dość pilna sprawa)
Nikt nie jest w stanie mi pomóc?
Cześć.
Udało mi się rozwiązać ten problem.
Fragment:
$response = json_encode(simplexml_load_string($val->getResponseBody()));
print "<pre>" . print_r(json_decode
($response, true), true) . "</pre>";
Zamieniamy na:
$xml = simplexml_load_string($val->getResponseBody());
$xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
foreach ($xml->entry as $entry) {
foreach ($entry->xpath('gd:email') as $email) {
$output_array[] = array((string
)$entry->title, (string
)$email->attributes()->address); }
}