I'm trying to create an Instagram app using the Yii framework and the Yii extension yiinstagram. I can connect to Instagram successfully but I cannot retrieve all of the current user's profile data. Here's the code I have put in a controller to connect to Instagram and retrieve the user data.
public function actionIndex()
{
$instagram = Yii::app()->instagram->getInstagramApp();
if (isset($_GET['code']))
{
$accessToken=$instagram->getAccessToken();
Yii::app()->session['InstagramAccessToken']= $accessToken;
$instagram->setAccessToken(Yii::app()->session['InstagramAccessToken']);
$instagramUser=$instagram->getCurrentUser();
Yii::app()->session['InstagramUser'] = $instagramUser;
$userFeed = $instagram->getUserFeed();
$this->render('index', array('userFeed'=>$userFeed));
}
else
{
echo "Could not retrieve code variable";
}
}
I take the session variable containing the current user's instagram profile data and put it in this php page that is associated with another controller:
<?php
/* @var $this LoginController */
$this->pageTitle=Yii::app()->name . ' - Instagram Profile';
?>
<h1>Instagram Profile</h1>
<div class="row">
<div class="span3"><img src="<?php echo Yii::app()->session['InstagramUser']->profile_picture;?>"/></div>
<div class="span7">
<ul>
<li><b>username:</b><?php echo Yii::app()->session['InstagramUser']->username;?></li>
<li><b>full name:</b><?php echo Yii::app()->session['InstagramUser']->full_name;?></li>
<li><b>bio:</b><?php echo Yii::app()->session['InstagramUser']->bio;?></li>
<li><b>website:</b><?php echo Yii::app()->session['InstagramUser']->website;?></li>
<li><b>photos:</b><?php echo Yii::app()->session['InstagramUser']->counts->media;?></li>
<li><b>followers:</b><?php echo Yii::app()->session['InstagramUser']->counts->followed_by;?></li>
<li><b>follows:</b><?php echo Yii::app()->session['InstagramUser']->counts->follows;?></li>
</ul>
<?php echo var_dump(Yii::app()->session['InstagramUser']); ?>
</div>
The values from the child object "counts" (media, followed_by, follows) do not display even though the rest of data from the session variable displays. I did a var_dump of Yii::app()->session['InstagramUser'] and this is what I got:
object(stdClass)#22 (6) {
["username"]=> string(9) "mdailey77"
["bio"]=> string(36) "photographer and avid Photoshop user"
["website"]=> string(25) "http://www.mattdailey.net"
["profile_picture"]=> string(72) "http://images.instagram.com/profiles/profile_3586295_75sq_1345911013.jpg"
["full_name"]=> string(14) "Matthew Dailey"
["id"]=> string(7) "3586295" }
The "counts" child object should have shown up right before "id". How can I get the values from the "counts" child object to display? I've been agonizing over this the last three days, so any help would be greatly appreciated. Thanks.
Not sure if this would help, but using the same endpoint url this is the response I get using Instagram's own API console:
{
"meta": {
"code": 200
},
"data": {
"username": "mdailey77",
"bio": "photographer and avid Photoshop user",
"website": "http://www.mattdailey.net",
"profile_picture": "http://images.instagram.com/profiles/profile_3586295_75sq_1345911013.jpg",
"full_name": "Matthew Dailey",
"counts": {
"media": 167,
"followed_by": 24,
"follows": 30
},
"id": "3586295"
}
}