コード例 #1
0
 /**
  * @param $data
  * @return Post[]
  */
 public function format($data)
 {
     $result = [];
     if (!$data) {
         return $result;
     }
     /** @var Media $media */
     foreach ($data as $media) {
         $post = new Post();
         $post->setUsername($media->getUser()->getUserName());
         $post->setProfileImageUrl($media->getUser()->getProfilePicture());
         $post->setUserUrl(self::INSTAGRAM_URL . $media->getUser()->getUserName());
         $post->setUrl($media->getData()->link);
         $post->setContent($media->getCaption()->getText());
         $post->setHashtags($media->getTags()->toArray());
         $post->setDate(\DateTime::createFromFormat('U', $media->getCreatedTime()));
         if (isset($media->getData()->videos)) {
             $post->setMedia($media->getStandardResVideo());
             $post->getMedia()->type = 'video';
         } else {
             $post->setMedia($media->getStandardResImage());
             $post->getMedia()->type = 'image';
         }
         $result[] = $post;
     }
     return $result;
 }
コード例 #2
0
 /**
  * @param $data
  * @return Post[]
  */
 public function format($data)
 {
     $result = [];
     if (is_object($data) && property_exists($data, 'statuses')) {
         foreach ($data->statuses as $status) {
             if (!$this->options['includeRetweets'] && property_exists($status, 'retweeted_status')) {
                 continue;
             }
             $post = new Post();
             $post->setUsername($status->user->name);
             $post->setUserUrl(self::TWITTER_URL . $status->user->screen_name);
             $post->setUrl(self::TWITTER_URL . $status->user->screen_name . '/status/' . $status->id);
             $post->setContent($status->text);
             $post->setHashtags($status->entities->hashtags);
             $post->setDate(new \DateTime($status->created_at));
             $post->setProfileImageUrl($status->user->profile_image_url);
             $result[] = $post;
         }
     }
     return $result;
 }