From 28adced5b6a0c56d0bbc1ed15d2e57c4383cf420 Mon Sep 17 00:00:00 2001 From: raiym Date: Mon, 6 Nov 2017 21:20:50 +0900 Subject: [PATCH] End with refactoring --- README.md | 65 -------------------- examples/convertShortcode.php | 16 +++++ examples/getCurrentTopMediasByLocationId.php | 24 ++++++++ examples/getCurrentTopMediasByTagName.php | 24 ++++++++ examples/getMediasByLocationId.php | 24 ++++++++ examples/getMediasByTag.php | 24 ++++++++ examples/getPaginateMediasByTag.php | 15 +++++ src/InstagramScraper/Instagram.php | 15 ++--- 8 files changed, 135 insertions(+), 72 deletions(-) create mode 100644 examples/convertShortcode.php create mode 100644 examples/getCurrentTopMediasByLocationId.php create mode 100644 examples/getCurrentTopMediasByTagName.php create mode 100644 examples/getMediasByLocationId.php create mode 100644 examples/getMediasByTag.php create mode 100644 examples/getPaginateMediasByTag.php diff --git a/README.md b/README.md index 4ca33946..bb447242 100644 --- a/README.md +++ b/README.md @@ -38,70 +38,5 @@ You can download it [here](https://getcomposer.org/download/). ## Examples See examples [here](https://github.com/postaddictme/instagram-php-scraper/tree/master/examples). - - -### Some of following examples outdated (fixing it) - -if you need to get medias by tags or locations: -```php -$instagram = Instagram::withCredentials('username', 'password'); -$instagram->login(); -// And then you will be able to query instagram with newly updated methods. (Notice that these methods are not static anymore) - -$medias $instagram->getLocationTopMediasById(1) -$medias = $instagram->getLocationMediasById(1); -$medias = $instagram->getTopMediasByTagName('hello'); -``` - -### Search medias by tag name -```php -$medias = Instagram::getMediasByTag('zara', 30); -echo json_encode($medias); -``` - -### Paginate medias by tag name -```php -$result = Instagram::getPaginateMediasByTag('zara'); -$medias = $result['medias'] - -if($result['hasNextPage'] === true) { - $result = Instagram::getPaginateMediasByTag('zara', $result['maxId']); - $medias = array_merge($medias, $result['medias']); -} - -echo json_encode($medias); -``` - -### Get top medias by tag name -```php -$medias = Instagram::getTopMediasByTagName('durov'); -``` -### Convert media id to shortcode -```php -echo 'CODE: ' . Media::getCodeFromId('1270593720437182847_3'); -// OR -echo 'CODE: ' . Media::getCodeFromId('1270593720437182847'); -// OR -echo 'CODE: ' . Media::getCodeFromId(1270593720437182847); -// CODE: BGiDkHAgBF_ -// So you can do like this: instagram.com/p/BGiDkHAgBF_ -``` - -### Convert shortcode to media id -```php -echo 'Media id: ' . Media::getIdFromCode('BGiDkHAgBF_'); -// Media id: 1270593720437182847 -``` - -### Get location top medias by location id -```php -$medias = Instagram::getLocationTopMediasById(1); -``` - -### Get location medias by location id -```php -$medias = Instagram::getLocationMediasById(1); -``` - ## Other Java library: https://github.com/postaddictme/instagram-java-scraper \ No newline at end of file diff --git a/examples/convertShortcode.php b/examples/convertShortcode.php new file mode 100644 index 00000000..8079ace3 --- /dev/null +++ b/examples/convertShortcode.php @@ -0,0 +1,16 @@ +login(); + +$medias = $instagram->getCurrentTopMediasByLocationId('1'); +$media = $medias[0]; +echo "Media info:\n"; +echo "Id: {$media->getId()}\n"; +echo "Shotrcode: {$media->getShortCode()}\n"; +echo "Created at: {$media->getCreatedTime()}\n"; +echo "Caption: {$media->getCaption()}\n"; +echo "Number of comments: {$media->getCommentsCount()}"; +echo "Number of likes: {$media->getLikesCount()}"; +echo "Get link: {$media->getLink()}"; +echo "High resolution image: {$media->getImageHighResolutionUrl()}"; +echo "Media type (video or image): {$media->getType()}"; +$account = $media->getOwner(); +echo "Account info:\n"; +echo "Id: {$account->getId()}\n"; +echo "Username: {$account->getUsername()}\n"; +echo "Full name: {$account->getFullName()}\n"; +echo "Profile pic url: {$account->getProfilePicUrl()}\n"; diff --git a/examples/getCurrentTopMediasByTagName.php b/examples/getCurrentTopMediasByTagName.php new file mode 100644 index 00000000..dfd83aa5 --- /dev/null +++ b/examples/getCurrentTopMediasByTagName.php @@ -0,0 +1,24 @@ +login(); + +$medias = $instagram->getCurrentTopMediasByTagName('youneverknow'); +$media = $medias[0]; +echo "Media info:\n"; +echo "Id: {$media->getId()}\n"; +echo "Shotrcode: {$media->getShortCode()}\n"; +echo "Created at: {$media->getCreatedTime()}\n"; +echo "Caption: {$media->getCaption()}\n"; +echo "Number of comments: {$media->getCommentsCount()}"; +echo "Number of likes: {$media->getLikesCount()}"; +echo "Get link: {$media->getLink()}"; +echo "High resolution image: {$media->getImageHighResolutionUrl()}"; +echo "Media type (video or image): {$media->getType()}"; +$account = $media->getOwner(); +echo "Account info:\n"; +echo "Id: {$account->getId()}\n"; +echo "Username: {$account->getUsername()}\n"; +echo "Full name: {$account->getFullName()}\n"; +echo "Profile pic url: {$account->getProfilePicUrl()}\n"; diff --git a/examples/getMediasByLocationId.php b/examples/getMediasByLocationId.php new file mode 100644 index 00000000..ab2b9dc3 --- /dev/null +++ b/examples/getMediasByLocationId.php @@ -0,0 +1,24 @@ +login(); + +$medias = $instagram->getMediasByLocationId('1', 20); +$media = $medias[0]; +echo "Media info:\n"; +echo "Id: {$media->getId()}\n"; +echo "Shotrcode: {$media->getShortCode()}\n"; +echo "Created at: {$media->getCreatedTime()}\n"; +echo "Caption: {$media->getCaption()}\n"; +echo "Number of comments: {$media->getCommentsCount()}"; +echo "Number of likes: {$media->getLikesCount()}"; +echo "Get link: {$media->getLink()}"; +echo "High resolution image: {$media->getImageHighResolutionUrl()}"; +echo "Media type (video or image): {$media->getType()}"; +$account = $media->getOwner(); +echo "Account info:\n"; +echo "Id: {$account->getId()}\n"; +echo "Username: {$account->getUsername()}\n"; +echo "Full name: {$account->getFullName()}\n"; +echo "Profile pic url: {$account->getProfilePicUrl()}\n"; diff --git a/examples/getMediasByTag.php b/examples/getMediasByTag.php new file mode 100644 index 00000000..8f6afcf8 --- /dev/null +++ b/examples/getMediasByTag.php @@ -0,0 +1,24 @@ +login(); + +$medias = $instagram->getMediasByTag('youneverknow', 20); +$media = $medias[0]; +echo "Media info:\n"; +echo "Id: {$media->getId()}\n"; +echo "Shotrcode: {$media->getShortCode()}\n"; +echo "Created at: {$media->getCreatedTime()}\n"; +echo "Caption: {$media->getCaption()}\n"; +echo "Number of comments: {$media->getCommentsCount()}"; +echo "Number of likes: {$media->getLikesCount()}"; +echo "Get link: {$media->getLink()}"; +echo "High resolution image: {$media->getImageHighResolutionUrl()}"; +echo "Media type (video or image): {$media->getType()}"; +$account = $media->getOwner(); +echo "Account info:\n"; +echo "Id: {$account->getId()}\n"; +echo "Username: {$account->getUsername()}\n"; +echo "Full name: {$account->getFullName()}\n"; +echo "Profile pic url: {$account->getProfilePicUrl()}\n"; diff --git a/examples/getPaginateMediasByTag.php b/examples/getPaginateMediasByTag.php new file mode 100644 index 00000000..311d1d62 --- /dev/null +++ b/examples/getPaginateMediasByTag.php @@ -0,0 +1,15 @@ +login(); + +$result = $instagram->getPaginateMediasByTag('zara'); +$medias = $result['medias']; + +if ($result['hasNextPage'] === true) { + $result = $instagram->getPaginateMediasByTag('zara', $result['maxId']); + $medias = array_merge($medias, $result['medias']); +} + +echo json_encode($medias); \ No newline at end of file diff --git a/src/InstagramScraper/Instagram.php b/src/InstagramScraper/Instagram.php index 79180f10..d1c22812 100644 --- a/src/InstagramScraper/Instagram.php +++ b/src/InstagramScraper/Instagram.php @@ -477,8 +477,9 @@ public function getAccount($username) * @param string $tag * @param int $count * @param string $maxId + * @param string $minTimestamp * - * @return array + * @return Media[] * @throws InstagramException */ public function getMediasByTag($tag, $count = 12, $maxId = '', $minTimestamp = null) @@ -592,11 +593,11 @@ public function getPaginateMediasByTag($tag, $maxId = '') /** * @param $tagName * - * @return array + * @return Media[] * @throws InstagramException * @throws InstagramNotFoundException */ - public function getTopMediasByTagName($tagName) + public function getCurrentTopMediasByTagName($tagName) { $response = Request::get(Endpoints::getMediasJsonByTagLink($tagName, ''), $this->generateHeaders($this->userSession)); @@ -619,11 +620,11 @@ public function getTopMediasByTagName($tagName) /** * @param $facebookLocationId * - * @return array + * @return Media[] * @throws InstagramException * @throws InstagramNotFoundException */ - public function getLocationTopMediasById($facebookLocationId) + public function getCurrentTopMediasByLocationId($facebookLocationId) { $response = Request::get(Endpoints::getMediasJsonByLocationIdLink($facebookLocationId), $this->generateHeaders($this->userSession)); @@ -649,10 +650,10 @@ public function getLocationTopMediasById($facebookLocationId) * @param int $quantity * @param string $offset * - * @return array + * @return Media[] * @throws InstagramException */ - public function getLocationMediasById($facebookLocationId, $quantity = 12, $offset = '') + public function getMediasByLocationId($facebookLocationId, $quantity = 12, $offset = '') { $index = 0; $medias = [];