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); $client->authenticate(); $_SESSION['token'] = $client->getAccessToken(); $redirect = 'http://www.domain.xx/admin/others/google'; } $client->setAccessToken($_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())); $_SESSION['token'] = $client->getAccessToken(); } else { $auth = $client->createAuthUrl(); } $auth = $client->createAuthUrl();
I otrzymuję przykład:
[24] => Array ( [updated] => 2016-03-13T21:13:40.065Z [category] => Array ( [@attributes] => Array ( ) ) [title] => Array ( [@attributes] => Array ( [type] => text ) ) [link] => Array ( [0] => Array ( [@attributes] => Array ( [type] => image/* ) ) [1] => Array ( [@attributes] => Array ( [rel] => self [type] => application/atom+xml ) ) [2] => Array ( [@attributes] => Array ( [rel] => edit [type] => application/atom+xml ) ) ) )
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()));
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) { } }