Reputation: 270
I'm trying to access "screen_name" data sent by oauth api. I'm getting "Trying to get property of non-object" error.
My current php code is this;
foreach($multi_responses as $response){
echo $response->user->screen_name;
}
This is the data sent by oauth: http://pastebin.com/SJbmYggQ
Upvotes: 0
Views: 602
Reputation: 24
As I see, you have got an array as a response, which is contains JSON strings. Try to parse JSON strings into an array or an object. If your $multi_responses variable in the foreach is fully contains the content of your linked file.
Array version:
<?php
foreach($multi_responses as $response){
$jsonDecodeArray = json_decode($response, true);
if( isset($jsonDecodeArray['user']['screen_name']) ){
echo $jsonDecodeArray['user']['screen_name'];
}
}
?>
Object version:
<?php
foreach($multi_responses as $response){
$jsonDecodeOBJ = json_decode($response);
if( isset($jsonDecodeOBJ->user->screen_name) ){
echo $jsonDecodeOBJ->user->screen_name;
}
}
?>
Upvotes: 1