Giter VIP home page Giter VIP logo

php-instagram-api's Introduction

#PHP Instagram API

This is a PHP 5.3+ API wrapper for the Instagram API

The API comes with a cURL client (Instagram\Net\CurlClient) to access the Instagran API. You can create your own client, it just has to implement Instagram\Net\ClientInterface.


##The API

All methods that access the API can throw exceptions. If the API request fails for any reason other than an expired/missing access token an exception of type \Instagram\Core\ApiException will be thrown. If the API request fails because of an expired/missing access token an exception of type \Instagram\Core\ApiAuthException will be thrown. You can use this to redirect to your authorization page.

##Authentication

$auth_config = array(
    'client_id'         => '',
    'client_secret'     => '',
    'redirect_uri'      => '',
    'scope'             => array( 'likes', 'comments', 'relationships' )
);

$auth = new Instagram\Auth( $auth_config );
  • Then you have to get the user to authorize your app

$auth->authorize();
  • This will redirect the user to the Instagram authorization page. After authorization Instagram will redirect the user to the url in $auth_config['redirect_uri'] with a code that you will need to obtain an access token

$_SESSION['instagram_access_token'] = $auth->getAccessToken( $_GET['code'] );
  • Then use the access token in your code

$instagram = new Instagram\Instagram;
$instagram->setAccessToken( $_SESSION['instagram_access_token'] );
$current_user = $instagram->getCurrentUser();

##Basic Usage

$instagram = new Instagram\Instagram( $_SESSION['instagram_access_token'] );
$user = $instagram->getUser( $user_id );
$media = $instagram->getMedia( $media_id );
$tag = $instagram->getTag( 'mariokart' );
$location = $instagram->getLocation( 3001881 );
$current_user = $instagram->getCurrentUser();

##Current User

The current user object will give you the currently logged in user

$current_user = $instagram->getCurrentUser();

With this object you can:

  • follow, unfollow, block, and unblock users

$current_user->follow( $user );
$current_user->unfollow( $user );
$current_user->block( $user );
$current_user->unblock( $user );
  • obtain the user's feed, liked media, follow requests

$feed = $current_user->getFeed();
$liked_media = $current_user->getLikedMedia();
  • ignore and approve follow requests

$current_user->ignoreFollowRequest( $user );
$current_user->approveFollowRequest( $user );

You can also perform all the functions you could on a normal user

##Getting Media

Users, tags, locations, and the current user have media associated with them.

This will return recent media from the 4 objects:

$user->getMedia();
$tag->getMedia();
$location->getMedia();
$current_user->getMedia();

You can pass an array of parameters to getMedia(). These parameters will be passed directly to the API. Check the API for a list of available parameters.

$user->getMedia(
    array( 'count' => 3 )
);
$tag->getMedia(
    array( 'max_tag_id' => $max_tag_id )
);
$location->getMedia(
    array( 'max_id' => $max_id )
);

##Images and Videos

You can distinguish between images and videos with Media::getType(). This will return video or image. Video files can be accessed with Media::getStandardResVideo() and Media::getLowResVideo(). The image methods on a video will return a still of the video.

##Collections

When making a call to a method that returns more than one of something (e.g. getMedia(), searchUsers() ), a collection object will be returned. Collections can be iterated, counted, and accessed like arrays.

$user = $instagram->getUser( $user_id );
$media = $user->getMedia();
foreach( $media as $photo ) {
     ...
}
$media_count = count( $media );
$first_photo = $media[0];

The collection object will sometimes have an identifier to the "next page" that can be used to obtain the next page of the collection.

To obtain the identifier for the next page you call getNext() on the collection object.

For example:

$user = $instagram->getUser( $user_id );
$media = $user->getMedia();
$next_page = $media->getNext();

Example usage:

<a href="user_media.php?max_id=<?php echo $next_page ?>">

In user_media.php you would check for a next page when obtaining the user media.

$user = $instagram->getUser( $user_id );
$params = isset( $_GET['max_id'] ) ? array( 'max_id' => $_GET['max_id'] ) : null;
$media = $user->getMedia( $params );

Unfortunately API methods require different params to be passed to them in order to obtain the next set of results (e.g. Tags require the max_tag_id param ).

##Searching

You can search for locations, media, tags, and users.

$locations = $instagram->searchLocations( $lat, $lng );
$media = $instagram->searchMedia( $lat, $lng );
$tags = $instagram->searchTags( 'tag' );
$users = $instagram->searchUsers( 'username' );

php-instagram-api's People

Contributors

agiuliano avatar galen avatar zeantsoi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-instagram-api's Issues

Tag the stable release

Would be great if it will be some stable release tagged in this repo (branch or tag).
I'm afraid of using "master" in composer.json

error

Notice: Undefined variable: auth_config in /Volumes/B/Dropbox/i.local/examples/_auth.php on line 7

Notice: Use of undefined constant EXAMPLES_DIR - assumed 'EXAMPLES_DIR' in /Volumes/B/Dropbox/i.local/examples/_auth.php on line 19

Warning: require(EXAMPLES_DIR/views/_header.php): failed to open stream: No such file or directory in /Volumes/B/Dropbox/i.local/examples/_auth.php on line 19

Fatal error: require(): Failed opening required 'EXAMPLES_DIR/views/_header.php' (include_path='.:/usr/local/Cellar/php54/5.4.15/lib/php') in /Volumes/B/Dropbox/i.local/examples/_auth.php on line 19

List of issues.

#1 No where in the Instagram system is there an APP_KEY.

You have a client_id, but by asking for a KEY vs and ID, you completely throw people off.
#2 ../ makes you go backwards a directory. git clone imports to PHP-Instagram-API, so if a party goes backward, that won't work either. So your require statement is broke.
#3 using composer? you can't, nobody knows the project name to use. Your instructions completely fail here too.

{
"require": {
"cosenary/Instagram-PHP-API": "2.2.*"
}
}

produces:

Problem 1
- The requested package cosenary/instagram-php-api could not be found in any version, there may be a typo in the package name.
#4

Something went wrong :(

I have no clue what this is supposed to mean. zero error handling. Your guess is as good as mine. Anywhere you put a var_dump(), you can't get to the output.

your software is broken because your instructions are so poor.

Tests are useless

You shouldn't use real data in your tests because it depends on their existence in database which you are not going to test. In InstagramTest.php you test a lot of functions using access_token (which is of course now expired) and that mean you test Instagram too, which is not your business. What if Instagram is down for a moment or real data you use doesn't exists any more (like access_token) and run your tests? Your tests will fail but it is not because your code is wrong.

Instead of that, tests should deal with mock objects and tests only your code separated from third parties because, in this case, we expect that Instagram API works well. That is not our business, we want to take care about our code only.

Accessing data

Hi,
I feel kind of stupid asking but I guess is worse not to leaner, I have installed the package on larvel and it seems to work fine but all data is protected , Ive try doing things like

$this->instagram = new Instagram\Instagram( $this->token );
$raw_data = $this->instagram->getTagMedia( $tag , array('count' => '100') );
$this->instagram->setData($raw_data);

but still Im not able to do
json_encode( $this->instagram->getData() );

since everything is coming back as protected...

Im I missing something? what would be the right way to access the data?

Thanks for any help

Not working with composer

Fatal error: Class 'Instagram\Instagram' not found...

Composer's autoload_namespaces is generating:

'Instagram' => $vendorDir . '/php-instagram-api/php-instagram-api/Instagram',

and should instead read:

'Instagram' => $vendorDir . '/php-instagram-api/php-instagram-api/.',

\ Error

Hey guys!

I'm trying to make an Instagram auth site.

register(); $auth_config = array( 'client_id' => 'dcbcbdb34ab04f108cb83942d13e5659', 'client_secret' => 'b6584624ed90408c8da3f9d6317a24b0', 'redirect_uri' => 'http://mypapr.com/instagram_callback.php', 'scope' => array( 'likes', 'comments', 'relationships' ) ``` ); ``` $auth = new Instagram\Auth($auth_config); echo($auth->getAccessToken($_GET['code'])); ``` /\* mysql_query("INSERT INTO `$email` VALUES ('instagram_access_token', '$access_token')"); */ ``` } else { } ``` } This is my code ^. When it runs I get this error: Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/mypapr/public_html/instagram_callback.php on line 31 Parse error: syntax error, unexpected T_STRING in /home/mypapr/public_html/instagram_callback.php on line 31 I'm completely lost as to how those backslashes even function... Can I get an explanation?

Accessing Tags without Auth

I'm unable to access a tag (e.g. #fun) without having to redirect the user to the Authentication page - even though the tags method doesn't need this

Post image at Instagram

Hey,

Can We able to post the image into the instagram?

I need to get Auth from the User to get the Access Token and then use that Access token to post image at instagram with same user's profile.

Can you please help me?

composer file issue

Hello, I don't want to use "composer.json" file. Is it possible to implement the codes without the "composer.json" file.

Regards.

Fatal error: Class 'Instagram\Core\BaseObjectAbstract' not found in C:\xampp\htdocs\domains\comealive\components\com_comealive\helpers\instagram\Media.php on line 25

Kept giving me this error for practically every file required. Had to solve it like this in Instagram.php

namespace Instagram;
require_once 'Core/BaseObjectAbstract.php';
require_once 'Core/Proxy.php';
require_once 'Net/ClientInterface.php';
require_once 'Net/CurlClient.php';
require_once 'Collection/CollectionAbstract.php';
require_once 'Collection/MediaCollection.php';
require_once 'Collection/TagMediaCollection.php';
require_once 'Net/ApiResponse.php';
require_once 'Media.php';

use \Instagram\Collection\MediaSearchCollection;
use \Instagram\Collection\TagCollection;
use \Instagram\Collection\TagMediaCollection;
....

Parse syntax error Instaphp.php Line 53

Hello,

I have downloaded the api, and upload the files at my server.

I opened Instaphp.php with my browser, and have the following error:
Parse error: syntax error, unexpected '[' in Instaphp.php on line 53

Is that a problem in the api script? I have nothing edited, only uploaded the files.

The code on Instaphp.php line 53:
private static $endpoints = [];

Tag a version

Can you please tag a version so we don't need to use dev-master which may have BC breaks?

Deprecated parameter when trying to get media from tag collection

API returns a deprecated warning when not specifying the parameters :

Called :
$tag = $instagram->getTag( 'nofilter' ); print_r($tag->getMedia());

Result :

Object@
(
    [pagination:protected] => stdClass Object
        (
            [deprecation_warning] => next_max_id and min_id are deprecated for this endpoint; use min_tag_id and max_tag_id instead
        )

    [data:protected] => Array
        (
        )

    [position:protected] => 
)

Load more button with images

Hey Galen,

I have got your Instagram PHP class working okay in my Laravel app.

I wondered how hard it would be to have a load more button in the site with images, say load more images obviously sticking to the Instagram amount every time so 20 loaded through the pagination->next_max_id. I have seen an example of it here https://gist.github.com/cosenary/2961185.

I just wondered how easy it would be with your PHP Library?

Cheers

Deprecation Warning

For the record, here is a deprecation warning : 'next_max_id and min_id are deprecated for this endpoint; use min_tag_id and max_tag_id instead'.

Fatal error: Class not found

Fatal error: Class 'Instagram\Core\Proxy' not found in C:\xampp\htdocs\Insta\Auth.php on line 54

Auth.php on line 54:
$this->proxy = new \Instagram\Core\Proxy( $client ? $client : new \Instagram\Net\CurlClient );

I hope someone help me with that, I try to solve it for 5 hours!

I have create index.php, and this the code inside:

'*deleted*', 'client_secret' => '*deleted*', 'redirect_uri' => '*deleted*', 'scope' => array( 'likes', 'comments', 'relationships' ) ); $auth = new Instagram\Auth( $auth_config ); if (isset($_GET['code']) && !empty($_GET['code'])){ $_SESSION['instagram_access_token'] = $auth->getAccessToken( $_GET['code'] ); echo 'ok'; }else{ $auth->authorize(); } ``` ?>

problem on new server with Media class

try to load current user page, get 500 error, logs says:

PHP Fatal error: Class '\Instagram\Media' not found in path-to-folder/Instagram/Collection/CollectionAbstract.php on line 124, referer: my-domain/Examples/

looks like some server settings wrong, but don't know which one...

server PHP Version 5.3.2-1ubuntu4.18

Check if access token is valid?

Is there any way of checking if access token is valid?

Would love something like this: $instagram->isAccessTokenValid($access_token);

Right now I am in a situation where I cannot get accesstoken through oauth2 and if the access token for some reason is not valid, then I get the exceptions thrown.

ApiException thrown when calling getTag('äää') with parameter including unicode chars

When I call

$instagram = new Instagram;
$instagram->setAccessToken('xxx');
$tag = $instagram->getTag('MyTäg');
$media = $tag->getMedia([]);

an Instagram\Core\ApiException is thrown with message 'Unknown Error'. When I remove the 'ä', it works fine. I have tried utf8_decode and iconv, but they have not helped.

The special characters get converted to something like MyT\xC3\xA4g which, of course, does not work in the URL https://api.instagram.com/v1/tags/<TAG>/media/recent

Codeing is according to java Should be in PHP

I just saw an issue with the library. That there problem to create objects of classes because the code is here are like java. And I am unable to use your library.
error are showing like this

Warning: Unexpected character in input: '' (ASCII=92) state=1 in /home/mytestse/public_html/instagram/Instagram/Auth.php on line 52

Warning: Unexpected character in input: '' (ASCII=92) state=1 in /home/mytestse/public_html/instagram/Instagram/Auth.php on line 52

Parse error: syntax error, unexpected T_STRING, expecting '&' or T_VARIABLE in /home/mytestse/public_html/instagram/Instagram/Auth.php on line 52

Thanks
Vishnu Dutt

ApiException: Problem (2) in the Chunked-Encoded data

Hi galen,

First, thanks a bunch for this library. I'm finding myself using it every once in a while through Composer and it's really nice.

I'm currently back working on a project I left aside for a couple of weeks, and found out my code using your library isn't working anymore :

$i = new Instagram\Instagram();
$i->setClientID('myclientid');
$test = $i->getTag('mytag')->getMedia()->getData();

This ends up with an "ApiException: Problem (2) in the Chunked-Encoded data". This exact same snippet used to work like a charm a couple weeks ago as I said ; I update my project's dependencies (including your library) through Composer on a regular basis, so I assume it's related to some change that occured in the meantime. Of course, I've tried various tags (no weird characters included, it's all [a-z]+) for the same result.

I can also tell you I already used your library on a previous project that went live before I start encountering this issue (which means I don't update its dependencies anymore), and it's still working, so I'm really positive this is caused by some recent change.

Could you please look into this ?

Regards,

Getting "Unknown Error" Exceptions randomly

I began getting comments from users of our web app (http://instaglimpse.com), that things were randomly not working. After some research, I realized that there was an exception being thrown in the AUTH part of the app, but the exception is simply "Unknown Error" — I came here to see if there were any updates and then tried to use your example site (http://galengrover.com/projects/instagram/) and encountered the same issue:
screen shot 2013-11-06 at 3 33 50 pm

I thought I'd open an issue here and see if anyone else has been encountering this random issue. Again, it happens every several requests. It has not been predictable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.