public function InstagramPostCollector::getPosts in Social Feed 8
Retrieve user's posts.
Parameters
int $numPosts: Number of posts to get.
string $user_id: The user id from whom to get media. Defaults to the user that the access token was created for.
Return value
array An array of Instagram posts.
File
- src/
Services/ InstagramPostCollector.php, line 102
Class
- InstagramPostCollector
- Class InstagramPostCollector.
Namespace
Drupal\socialfeed\ServicesCode
public function getPosts($numPosts, $user_id = 'me') {
$posts = [];
$response = $this->instagram
->getUserMedia($user_id, $numPosts);
if (isset($response->data)) {
$posts = array_map(function ($post) {
return [
'raw' => $post,
'media_url' => $post->media_url,
'type' => $post->media_type,
'children' => $post->children ?? NULL,
];
}, $response->data);
}
return $posts;
}