次の方法を使用して、Google コンタクトですべての連絡先を受信しています:
session_start();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/accounts/ClientLogin');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = array(
'accountType' => 'GOOGLE',
'Email' => 'email',
'Passwd' => 'password',
'source' => 'sourcetest',
'service' => 'cp'
);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$responses = explode("\n", curl_exec($ch));
$_SESSION['auth'] = str_replace('Auth=', '', $responses[2]);
$_SESSION['email'] = 'email';
$url = 'https://www.google.com/m8/feeds/contacts/default/full';
$url .= '?group=http://www.google.com/m8/feeds/groups/'.$_SESSION['email'].'/base/6';
$url .= '&max-results=500&alt=json';
$ch = curl_init($url);
$header[] = 'Authorization: GoogleLogin auth='.$_SESSION['auth'];
$header[] = 'GData-Version: 3.0';
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$response = curl_exec($ch);
curl_close($ch);
/** **** **** **** **** **** **** **** **** **** **** **/
# CONTROL
if(isset($response_as_array['feed']) AND isset($response_as_array['feed']['entry'])) {
# TABLE
echo '<table width="100%" cellpadding="0" cellspacing="0">';
echo '<tr>';
echo '<td align="left" class="padding-td" width="180">';
echo '<b>Namn</b>';
echo '</td>';
echo '<td align="left" class="padding-td">';
echo '<b>Telefon-nummer</b>';
echo '</td>';
echo '</tr>';
# LOOP
foreach($response_as_array['feed']['entry'] AS $i => $entry) {
# CONTROL: Hide my name
if(utf8_decode($entry['gd$name']['gd$fullName']['$t']) != 'Erik Edgren') {
echo '<tr>';
echo '<td align="left" class="padding-td">';
echo utf8_decode($entry['gd$name']['gd$fullName']['$t']);
echo '</td>';
echo '<td align="left" class="padding-td">';
echo isset($entry['gd$phoneNumber'][0]) ? $entry['gd$phoneNumber'][0]['$t'] : '';
echo '</td>';
echo '</tr>';
}
}
echo '</table>';
}
正常に動作しますが、連絡先をアルファベット順に並べ替えていません。これどうやってするの?
前もって感謝します。