https://github.com/jabranr/instagram-php-sdk
PHP client for Instagram API
https://github.com/jabranr/instagram-php-sdk
instagram-api instagram-php-sdk php php-client
Last synced: 11 months ago
JSON representation
PHP client for Instagram API
- Host: GitHub
- URL: https://github.com/jabranr/instagram-php-sdk
- Owner: jabranr
- License: mit
- Created: 2014-11-27T14:43:28.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2016-09-23T17:28:34.000Z (over 9 years ago)
- Last Synced: 2025-04-14T02:11:47.154Z (11 months ago)
- Topics: instagram-api, instagram-php-sdk, php, php-client
- Language: PHP
- Homepage:
- Size: 16.6 KB
- Stars: 4
- Watchers: 3
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Instagram PHP SDK [](https://travis-ci.org/jabranr/instagram-php-sdk) [](https://github.com/igrigorik/ga-beacon)
PHP client for Instagram API
> **Disclaimer:** Although this project shares same name with famous social network but is NOT an official version of PHP [SDKs for Instagram](http://github.com/Instagram). The package is provided as it is with no guarantee or promises so please use at your own risk. [Instagram](http://instagram.com) is product of Instagram/Facebook.
## Install & Usage
+ Download the [latest release](https://github.com/jabranr/instagram-php-sdk/releases/) or install using [Composer](http://getcomposer.org)
+ Register client at [http://instagram.com/developer/clients/register/](http://instagram.com/developer/clients/register/) and get `client_id`, `client_secret` and `redirect_uri`.
+ Here is a basic use example:
```php
require('path/to/autoload.php');
use Instagram\InstagramClient;
$config = array(
'client_id' => 'CLIENT_ID',
'client_secret' => 'CLIENT_SECRET',
'redirect_uri' => 'http://example.com'
);
try {
$ig = new InstagramClient( $config );
} catch (Exception $e) {
echo $e->getMessage();
}
if ( isset($ig) && $ig ) {
/**
* Get a new access token with OAuth
*/
if ( isset($_GET['code']) ) {
$ig->get_access_token( $fresh = true, $_GET['code'] );
print_r( $ig->get_data() );
/**
* Make API requests. See various methods underneath.
*/
}
/**
* Or display a login with Instagram link for redirect user for OAuth
*/
else {
echo 'Login with Insgatram';
}
/**
* Or set an existing access token
*/
$ig->set_access_token( 'A_valid_access_token_obtained_previously' );
print_r( $ig->get_data() );
/**
* Make API requests. See various methods underneath.
*/
}
```
## Documentation
Use following methods to make requests to Instagram API.
#### Get Popular Media
```php
try {
$media = $ig->popularMedia( (int) $count = 25 );
$media = json_decode( $media );
print_r( $media );
} catch(Exception $e) {
echo $e->getMessage();
}
```
#### Search Media
```php
/**
* Atleast lat and lng are required to make requests to this endpoint
*/
try {
$media = $ig->searchMedia(
(float) $lat,
(float) $lng,
(UNIX_TIMESTAMP) $min_timestamp,
(UNIX_TIMESTAMP) $max_timestamp,
(int) $distance,
(int) $count = 25 );
$media = json_decode( $media );
print_r( $media );
} catch(Exception $e) {
echo $e->getMessage();
}
```
#### Get Media using an ID
```php
try {
$media = $ig->getMedia( (int) $media_id );
$media = json_decode( $media );
print_r( $media );
} catch(Exception $e) {
echo $e->getMessage();
}
```
# License
MIT License - © [Jabran Rafique](http://jabran.me) 2014