Skip to content

Commit

Permalink
Add method for instagram feeder and config for instagram credantials
Browse files Browse the repository at this point in the history
  • Loading branch information
ymihaylov committed Feb 18, 2015
1 parent 1b962e1 commit d5ba0c7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/Despark/LaravelSocialFeeder/SocialFeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,41 @@ public static function updateFacebookPosts()

return true;
}

public static function updateInstagramPosts()
{
$lastInstagramPost = \SocialPost::type('instagram')->latest('published_at')->get()->first();
$lastInstagramPostTimestamp = $lastInstagramPost ? strtotime($lastInstagramPost->published_at) : 0;

$clientId = Config::get('laravel-social-feeder::instagramCredentials.clientId');
$userId = Config::get('laravel-social-feeder::instagramCredentials.userId');

$url = 'https://api.instagram.com/v1/users/'.$userId.'/media/recent?count=5&client_id='.$clientId;
$json = file_get_contents($url);

$obj = json_decode($json);

$postsData = $obj->data;

foreach ($postsData as $post)
{
if ( $post->caption->created_time <= $lastInstagramPostTimestamp)
continue;

$newPostData = array(
'type' => 'instagram',
'social_id' => $post->caption->id,
'url' => $post->link,
'text' => $post->caption->text,
'image_url' => $post->images->standard_resolution->url,
'show_on_page' => 1,
'published_at' => date('Y-m-d H:i:s', $post->caption->created_time),
);

$newPostEntity = new \SocialPost;
$newPostEntity->fill($newPostData)->save();
}

return true;
}
}
5 changes: 5 additions & 0 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@
'accessToken' => '{access_token}',
'pageName' => '{page_name}'
),

'instagramCredentials' => array(
'userId' => '{userId}',
'clientId' => '{clientId}',
),
);

0 comments on commit d5ba0c7

Please sign in to comment.