Example #1
0
 public function getByHash($hashtag)
 {
     if ($data = current($this->client->searchTags($hashtag)->getData())) {
         $data = $data->getMedia()->getData();
     }
     return $this->formatter->format($data);
 }
 public function fetchData()
 {
     $instagram = new Instagram();
     $instagram->setAccessToken(Application::getInstance()->config('instagram_token'));
     $this->_currentUser = $instagram->getCurrentUser();
     return $this->_currentUser instanceof \Instagram\CurrentUser;
 }
Example #3
0
File: Gram.php Project: smbale/eyew
 public function lookup($id)
 {
     $instagram = new Instagram\Instagram();
     $instagram->setClientID(\Yii::$app->params['instagram']['client_id']);
     $media = $instagram->getMedia($id);
     return $media;
 }
 private function getSocialHashtag($tag)
 {
     $socialHashtag = new SocialHashtag($tag);
     $instagram = new Instagram();
     $instagram->setClientID(INSTAGRAM_CLIENT_ID);
     $socialHashtag->addFeed(new InstagramFeed($instagram, new InstagramDataFormatter()));
     return $socialHashtag;
 }
Example #5
0
 public function getFeed($options)
 {
     $since_time = empty($options['sa_since_time']) ? 1 : $options['sa_since_time'];
     // $auth_config = array(
     // 	'client_id' => $options['sa_insta_client_id'],
     // 	'client_secret' => $options['sa_insta_client_secret'],
     // 	'redirect_uri' => $options['sa_insta_callback'],
     // 	'scope' => array('basic')
     // );
     // $auth = new Instagram\Auth($auth_config);
     // if (!empty($_GET['code'])) {
     // 	$_SESSION['instagram_access_token'] = $auth->getAccessToken($_GET['code']);
     // }
     // else {
     // 	$auth->authorize();
     // }
     // $this->log($_SESSION['instagram_access_token']);
     $instagram = new Instagram();
     $instagram->setAccessToken($options['sa_insta_access_token']);
     try {
         // $user = $instagram->getUser('343124091');
         $user = $instagram->getUserByUsername($options['sa_insta_screenname']);
         // $user = $instagram->getTag('freefly'); // if wanting to use tags..
         $media = $user->getMedia(array('min_timestamp' => $since_time));
     } catch (ApiException $e) {
         $this->log($e);
         return array('error' => 4, 'message' => 'Error fetching Instagram feed: <span class="social-feed-error">' . $e->getMessage() . '</span>');
     }
     // return an array with success = false if $response is empty..
     if (count($media) == 0) {
         return array('error' => 1, 'message' => 'No Instagram items found.');
     }
     $data = array();
     $date_added = time();
     $since_ids = array();
     foreach ($media as $photo) {
         $p = array();
         $p['id'] = $photo->getId();
         $p['author'] = $photo->getUser()->getUserName();
         if ($photo->getCaption()) {
             $p['message'] = $photo->getCaption()->text;
         }
         $p['picture'] = $photo->getStandardResImage()->url;
         $p['link'] = $photo->getLink();
         $p['date_added'] = $date_added;
         $p['date_created'] = $photo->getCreatedTime();
         // already a unix timestamp..
         $since_ids[] = $photo->getCreatedTime();
         array_push($data, $p);
     }
     if (count($data) == 0) {
         return array('error' => 3, 'message' => 'No new Instagram items found.');
     }
     $res = array('data' => $data, 'since_time' => max($since_ids) + 1);
     // someone somewhere must be using => instead of >, so I'm adding 1 here to not include the equality..
     return $res;
 }
Example #6
0
 public function searchInstagram()
 {
     $instagram = new Instagram\Instagram();
     $instagram->setClientID(\Yii::$app->params['instagram']['client_id']);
     $end_at = $this->start_at + $this->duration * 60;
     $params = array('min_timestamp' => $this->start_at, 'max_timestamp' => $end_at, 'distance' => $this->distance, 'count' => 50);
     $media = $instagram->searchMedia($this->latitude, $this->longitude, $params);
     foreach ($media as $m) {
         if (isset($m->caption->text)) {
             $caption = $m->caption->text;
         } else {
             $caption = '';
         }
         $i = new Gram();
         $i->add($this->id, $m->user->username, $m->link, $m->created_time, $m->images->thumbnail->url, $caption);
     }
 }
Example #7
0
 public function onRun()
 {
     $key = $this->makeKey();
     if (Cache::has($key)) {
         $this->media = $this->page['media'] = Cache::get($key);
     } else {
         $settings = Settings::instance();
         $api = new Instagram();
         $api->setClientID($settings->client_id);
         if ($settings->access_token) {
             $api->setAccessToken($settings->access_token);
         }
         $this->media = $this->page['media'] = $api->getTagMedia($this->property('tag'), array('count' => $this->property('limit', 10)));
         $expires_at = Carbon::now()->addMinutes($this->property('cache'));
         Cache::put($key, $this->media, $expires_at);
     }
 }
Example #8
0
 public function onRun()
 {
     $key = $this->makeKey();
     if (Cache::has($key)) {
         $this->single = $this->page['single'] = Cache::get($key);
     } else {
         $settings = Settings::instance();
         $api = new Instagram();
         $api->setClientID($settings->client_id);
         if ($settings->access_token) {
             $api->setAccessToken($settings->access_token);
         }
         // Get the shortcode from the url
         $parts = explode('/p/', $this->property('url'));
         $parts = explode('/', $parts[1]);
         $shortcode = $parts[0];
         // Now get the media info
         $this->single = $this->page['single'] = $api->getMediaByShortcode($shortcode);
         // Cache it
         $expires_at = Carbon::now()->addMinutes($this->property('cache'));
         Cache::put($key, $this->single, $expires_at);
     }
 }
 /**
  *
  * Execute the Request
  *
  * @return object Response Data
  * @throws InstagramException
  */
 public function execute()
 {
     $response = parent::execute();
     $this->response = $response;
     if ($this->interceptResponse($response)) {
         return null;
     }
     if ($this->throwExceptionIfResponseNotOk() && !$response->isOK() && !$response->isJson()) {
         return $response->getCode();
     }
     $this->instagram->setCookies(array_merge($this->instagram->getCookies(), $response->getCookies()));
     if ($this->parseResponse()) {
         return $this->mapper->map($response->getData(), $this->getResponseObject());
     }
     return $response->getData();
 }
Example #10
0
<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once __DIR__ . '/Instagram/Instagram.php';
require_once __DIR__ . '/Instagram/Exception/InstagramException.php';
use Instagram\Instagram;
/* create Instagram class with just client id. These will be unauthed requests. */
$client_id = 'YOUR CLIENT ID';
$instagram = new Instagram($client_id);
$res = $instagram->get('/media/popular');
// User endpoints.
$callParams = array('q' => 'dennis');
$res = $instagram->get('/users/search', $callParams);
$res = $instagram->get('/users/3');
// This will fail because it needs an access token.
$callParams = array('count' => 10);
//$res = $instagram->get('/users/self/feed', $callParams);
$callParams = array('count' => 10);
$res = $instagram->get('/users/3/media/recent', $callParams);
var_dump($res);
Example #11
0
<?php

use instagram\Instagram;
require dirname(__FILE__) . '/src/Instagram.php';
$instagram = new Instagram(['name' => 'value']);
$instagram->login('basic');
#$instagram->auth('code');
#$instagram->search('tag');
#$instagram->follow('user-id');
#$instagram->likeMedia('media-id');
#$instagram->commentMedia('media-id', 'comment');
<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once __DIR__ . '/Instagram/Instagram.php';
require_once __DIR__ . '/Instagram/Exception/InstagramException.php';
use Instagram\Instagram;
/* create Instagram class with set tokens
 */
$code = !empty($_GET['code']) ? $_GET['code'] : '';
$client_id = 'YOUR CLIENT ID';
$client_secret = 'YOUR SECRET';
$redirect = 'http://localhost:8081/InstagramPhpApi/demo_auth.php';
$instagram = new Instagram($client_id, $client_secret, $redirect);
?>
<a href="<?php 
echo $instagram->getAuthUrl();
?>
">Authorize</a>

<?php 
if ($code != '') {
    $instagram->getAccessToken($code);
    $user = $instagram->getUser();
    $res = $instagram->get('/media/popular');
    $res = $instagram->get('/users/self/media/liked');
    var_dump($res);
}
if ($code != '') {
    ?>
<p>User: <?php