-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented media::hasLiked() and added function to example likeAndUn…
…likeMdeia.php (#835)
- Loading branch information
Showing
2 changed files
with
50 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,45 @@ | ||
<?php | ||
ini_set('display_errors', 1);ini_set('display_startup_errors', 1);error_reporting(E_ALL); | ||
use Phpfastcache\Helper\Psr16Adapter; | ||
use InstagramScraper\Exception\InstagramException; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files')); | ||
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'user', 'passwd', new Psr16Adapter('Files')); | ||
$instagram->login(); | ||
|
||
$mediaId='2474033634010898853'; | ||
|
||
function loghasLiked($bool) | ||
{ | ||
echo "HasLiked: "; | ||
var_export($bool); | ||
if ($bool === null) echo " -> Unknown\n<br>"; //e.g. getMedia by tag won't give us haslike (-> an additional call to getMediaByCode/Id will give the result) | ||
elseif ($bool) echo " -> Liked\n<br>"; | ||
else echo " -> Not Liked\n<br>"; | ||
} | ||
|
||
try { | ||
$instagram->like('1663256735663694497'); | ||
$instagram->unlike('1663256735663694497'); | ||
loghasLiked($instagram->getMediaById($mediaId)->getHasLiked()); | ||
//hasLiked: False -> Not Liked | ||
|
||
$instagram->like($mediaId); | ||
loghasLiked($instagram->getMediaById($mediaId)->getHasLiked()); | ||
//hasLiked: True -> Liked | ||
|
||
$instagram->unlike($mediaId); | ||
loghasLiked($instagram->getMediaById($mediaId)->getHasLiked()); | ||
//hasLiked: False -> Not Liked | ||
|
||
echo "\n<br>"; | ||
$media = $instagram->getCurrentTopMediasByTagName('Photography')[0]; | ||
loghasLiked($media->getHasLiked()); | ||
//hasLiked: NULL -> Unknown | ||
|
||
$media = $instagram->getMediaById($media->getId()); | ||
loghasLiked($media->getHasLiked()); | ||
//hasLiked: False -> Not Liked | ||
|
||
} catch (InstagramException $ex) { | ||
echo $ex->getMessage(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters