Я успешно импортирую контакт электронной почты с yahoo Oauth API. И я вижу, что все мое контактное письмо указано на странице, когда я повторяю его. Однако, несмотря на успех печати электронной почты, есть сообщение об ошибке:
Trying to get property of non-object in globalses.php on line 295
И Undefined offset: 1 in globalses.php on line 295
Это код, который показывает, что ошибка:
if (! empty($response)) {
list($info, $header, $body) = $response;
if ($body) {
//logit("callcontact:INFO:response:");
//print(json_pretty_print($body));
$yahoo_array = json_decode($body);
echo "<pre/>";
//print_r($yahoo_array);
foreach($yahoo_array as $key=>$values){
foreach($values->contact as $keys=>$values_sub){
// echo '<pre/>';
// print_r($values_sub);
// echo $values_sub->fields[1]->value->givenName;
$email = $values_sub->fields[1]->value; //This is line 295
if(trim($email)!="")
$newList .= $email.",";
}
}
}
$retarr = $newList."";
}
return $retarr;
[UPDATE] $values->contact
результат $values->contact
Array
(
[0] => stdClass Object
(
[isConnection] =>
[id] => 50331977
[fields] => Array
(
[0] => stdClass Object
(
[id] => 50332026
[type] => email
[value] => [email protected]
[editedBy] => OWNER
[flags] => Array
(
)
[categories] => Array
(
)
)
)
[categories] => Array
(
)
[error] => 0
[restoredId] => 0
)
[1] => stdClass Object
(
[isConnection] =>
[id] => 41
[fields] => Array
(
[0] => stdClass Object
(
[id] => 63
[type] => email
[value] => [email protected]
[editedBy] => OWNER
[flags] => Array
(
)
[categories] => Array
(
)
)
)
[categories] => Array
(
)
[error] => 0
[restoredId] => 0
)
[2] => stdClass Object
(
[isConnection] =>
[id] => 50331986
[fields] => Array
(
[0] => stdClass Object
(
[id] => 50332036
[type] => email
[value] => [email protected]
[editedBy] => OWNER
[flags] => Array
(
)
[categories] => Array
(
)
)
[1] => stdClass Object
(
[id] => 50332037
[type] => guid
[value] => APQMLKWC3QLQRAMYZQABSF63ZA
[editedBy] => OWNER
[flags] => Array
(
[0] => Y360
)
[isConnection] =>
[categories] => Array
(
)
)
)
[categories] => Array
(
)
[error] => 0
[restoredId] => 0
)
[ОБНОВИТЬ]
foreach($values->contact as $keys=>$values_sub){
if(property_exists($values_sub, 'value') && !is_array($values_sub->value))
//echo $values_sub->fields[1]->value->givenName;
$email = $values_sub->fields[1]->value;
if(trim($email)!="")
$newList .= $email.",";
[UPDATE] результат var_dump
[email protected](31) "[email protected]"
[email protected](30) "[email protected]"
APQMLKWC3QLQRAMYZQABSF63ZAstring(26) "APQMLKWC3QLQRAMYZQABSF63ZA"
[email protected](25) "[email protected]"
[email protected](24) "[email protected]"
IKN34TUEMHOJNOBUJQP5D2CBDQstring(26) "IKN34TUEMHOJNOBUJQP5D2CBDQ"
[email protected](17) "[email protected]"
[email protected](31) "[email protected]"
[email protected](20) "[email protected]"
[email protected](18) "[email protected]"
[email protected](14) "[email protected]"
[email protected](22) "[email protected]"
[email protected](24) "[email protected]"
[email protected](33) "[email protected]"
Вы получаете доступ к электронной почте по своим полям:
$email = $values_sub->fields[1]->value; //This is line 295
Когда вы видите первый элемент массива, нет никаких полей с ключом 1, поскольку это только значение в массиве. $fields[0].
Увидев ваш код и фактический массив, я придумал следующее: это может быть не полное решение, а надежды на результат.
Так должно быть что-то вроде этого:
foreach($values->contact as $keys=>$values_sub){
$fields = $values_sub->fields;
foreach($fields as $field){
if(property_exists($field,'value') && !is_array($field->value)){
echo (string) $field->value;
}
}
}
$values_sub->fields[1]
доступ к $values_sub->fields[1]
. Попробуйте перебирать поля, а не обращаться к ним, как вы это сделали.