Merhabalar, instagram api’de istenilen kullanıcıyı takip etme, takipten çıkarma, engelleme gibi işlemlerin yapılması aşağıdaki gibidir. Ben https://github.com/cosenary/Instagram-PHP-API buradaki kütüphaneyi kullanıyorum ben size vericem fakat yinede indirebilirsiniz burdan. İlk olarak login alanı oluşturuyoruz. index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<?php require 'include/Instagram.php'; use MetzWeb\Instagram\Instagram; $instagram = new Instagram(array( 'apiKey' => '', 'apiSecret' => '', 'apiCallback' => 'http://localhost/www/tutorial/instagram/success.php' )); $loginUrl = $instagram->getLoginUrl(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Selam Instagram API</title> <style> .login { display: block; font-size: 20px; font-weight: bold; margin-top: 50px; } </style> </head> <body> <div class="container"> <a class="login" href="<?php echo $loginUrl ?>">» Login with Instagram</a> </div> </div> </body> </html> |
auth.php # Kontrol alanı
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<?php session_start(); require 'include/Instagram.php'; use MetzWeb\Instagram\Instagram; $instagram = new Instagram(array( 'apiKey' => '', 'apiSecret' => '', 'apiCallback' => 'http://localhost/www/tutorial/instagram/success.php' )); if (isset($_GET['code'])) { $data = $instagram->getOAuthToken($_GET['code']); $_SESSION['data'] = $data; $username = $data->user->username; $instagram->setAccessToken($data); $_SESSION['instagram'] = $instagram; $result = $instagram->getUserMedia(); header('Location: http://localhost/www/tutorial/instagram/home.php'); } else { if (isset($_SESSION['data'])){ $instagram->setAccessToken($_SESSION['data']); $usermedia = $instagram->getUserMedia(); # Kullanıcı resimleri } } ?> |
Yönlenecek dosya bunu istediğiniz gibi şekillendirebilirsiniz.
1 |
<?php include "include/auth.php"; ?> |
Ve bilgileri göstereceğimiz alan
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php include "include/auth.php"; ?> <meta charset="utf-8"/> <?php print_r($_SESSION['data']); ?> <br> <?=$_SESSION['data']->user->full_name;?> <br> <img src="<?=$_SESSION['data']->user->profile_picture;?>"/> <?php # Takip Etme #$instagram->modifyRelationship('follow','237926968'); userID Örnekteki şafak sezerin userID'si # follow/unfollow/block/unblock/approve/deny yapabileceğiniz işlemler #$instagram->modifyRelationship('follow','237926968'); ?> |
Takip etme işlemi[…]