dounue6984 2016-06-11 13:27
浏览 31

从谷歌意外的未定义索引中获取联系人

when user allow permission & script start processing every data is shown perfectly but i get error

PHP Notice: Undefined index: gd$email in

here is my php code

if (!empty($contacts['feed']['entry']))
    {
foreach($contacts['feed']['entry'] as $contact)
    {

    // retrieve user photo

    if (isset($contact['link'][0]['href']))
        {
        $url = $contact['link'][0]['href'];
        $url = $url . '&access_token=' . urlencode($accesstoken);
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_TIMEOUT, 15);
        curl_setopt($curl, CURLOPT_VERBOSE, true);
        $image = curl_exec($curl);
        curl_close($curl);
        }


    if ($image === 'Photo not found')
        {

        // retrieve Name and email address

        $return[] = array(
            'name' => $contact['title']['$t'],
            'email' => $contact['gd$email'][0]['address'],
            'img_url' => '//cdn.twkcdn.com/profile/image/avatar.png?w=40&h=40&cf',
        );
        }
      else
        {

        // retrieve Name and email address

        $return[] = array(
            'name' => $contact['title']['$t'],
            'email' => $contact['gd$email'][0]['address'],
            'img_url' => $url,
        );
        }
    }

$google_contacts = $return; //returning all d
}

This is just example of half script & i don't know why fetching contacts from google take about 15 to 20 seconds everytime i visit this page

  • 写回答

1条回答 默认 最新

  • dongshi1424 2016-12-05 10:04
    关注

    Google doesn't check that all entry has email address.

    Add that immediatly after Foreach :

    if (!array_key_exists('gd$email', $contact)){
        continue;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了