{"id":27154672,"url":"https://github.com/andreyco/instagram-for-php","last_synced_at":"2025-04-08T17:51:02.196Z","repository":{"id":25087452,"uuid":"28508248","full_name":"Andreyco/Instagram-for-PHP","owner":"Andreyco","description":"PHP SDK for Instagram API","archived":false,"fork":false,"pushed_at":"2019-01-04T06:01:37.000Z","size":169,"stargazers_count":80,"open_issues_count":3,"forks_count":34,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-15T13:48:25.366Z","etag":null,"topics":["instagram","laravel","laravel-package","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Andreyco.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-26T10:49:17.000Z","updated_at":"2024-10-28T19:50:22.000Z","dependencies_parsed_at":"2022-08-23T15:40:52.604Z","dependency_job_id":null,"html_url":"https://github.com/Andreyco/Instagram-for-PHP","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andreyco%2FInstagram-for-PHP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andreyco%2FInstagram-for-PHP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andreyco%2FInstagram-for-PHP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andreyco%2FInstagram-for-PHP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Andreyco","download_url":"https://codeload.github.com/Andreyco/Instagram-for-PHP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247897193,"owners_count":21014690,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["instagram","laravel","laravel-package","php"],"created_at":"2025-04-08T17:51:01.600Z","updated_at":"2025-04-08T17:51:02.189Z","avatar_url":"https://github.com/Andreyco.png","language":"PHP","readme":"![instagram-logo-400x400](https://user-images.githubusercontent.com/829963/27837919-95368730-60e7-11e7-8071-0ce79f35579b.png)\n# Instagram PHP API 4.1.1\n\nA PHP wrapper for the Instagram API.\nFeedback or bug reports are appreciated.\n\n\u003e Supports Laravel 5.3, 5.4 \u0026 5.5\n\n\u003e Now supports [Instagram video](#instagram-videos) responses.\n\n\n# Requirements\n- Registered Instagram App\n- PHP 5.3 or higher\n- cURL\n\n# Get started\n\nTo use the Instagram API with OAuth you have to register yourself as developer at the [Instagram Developer Platform](http://instagr.am/developer/register/) and set up an App. Take a look at the [uri guidlines](#samples-for-redirect-urls) before registering a redirect URI.\n\nPlease note that Instagram mainly refers to »Clients« instead of »Apps«. So »Client ID« and »Client Secret« are the same as »App Key« and »App Secret«.\n\n\u003e A good place to get started is the example App.\n\n## Initialize the class\n### Pure PHP\n```php\n\u003c?php\n    require '../vendor/autoload.php';\n\n\t$instagram = new Andreyco\\Instagram\\Client(array(\n      'apiKey'      =\u003e 'YOUR_APP_KEY',\n      'apiSecret'   =\u003e 'YOUR_APP_SECRET',\n      'apiCallback' =\u003e 'YOUR_APP_CALLBACK',\n      'scope'       =\u003e array('basic'),\n    ));\n\n    echo \"\u003ca href='{$instagram-\u003egetLoginUrl()}'\u003eLogin with Instagram\u003c/a\u003e\";\n?\u003e\n```\n### Laravel\nThis package offers Laravel support out of the box. These steps are required to setup the package.\n\n**Installation**\n```shell\ncomposer require andreyco/instagram\n```\n\n**Add Service provider and register Facade**\n\n```php\n'providers' =\u003e array(\n    // ...\n    Andreyco\\Instagram\\Support\\Laravel\\ServiceProvider\\Instagram::class,\n    // ...\n),\n\n'aliases' =\u003e array(\n    // ...\n    'Instagram' =\u003e Andreyco\\Instagram\\Support\\Laravel\\Facade\\Instagram::class,\n    // ...\n),\n```\n\n**Configuration**\n```php\n// Pushlish configuration file.\nphp artisan vendor:publish --provider=\"Andreyco\\Instagram\\Support\\Laravel\\ServiceProvider\\Instagram\"\n\n// Edit previously created `config/instagram.php` file\nreturn [\n    'clientId'     =\u003e '...',\n    'clientSecret' =\u003e '...',\n    'redirectUri'  =\u003e '...',\n    'scope'        =\u003e ['basic'],\n]\n```\n\n\n# Usage\nIn Laravel application, you can access library by simply using `Instagram` facade, e.g.\n```php\nInstagram::getLoginUrl();\n```\nFor usage in pure PHP, you have to create instance of class.\n\n```php\n$instagram = new Andreyco\\Instagram\\Client($config);\n$instagram-\u003egetLoginUrl()\n```\n\n## Authentication example\n```php\n\u003c?php\n    // Generate and redirect to login URL.\n    $url = Instagram::getLoginUrl();\n\n    // After allowing to access your profile, grab authorization *code* when redirected back to your page.\n    $code = $_GET['code'];\n    $data = Instagram::getOAuthToken($code);\n\n    // Now, you have access to authentication token and user profile\n    echo 'Your username is: ' . $data-\u003euser-\u003eusername;\n    echo 'Your access token is: ' . $data-\u003eaccess_token;\n?\u003e\n```\n\n## Get user likes example\n\n```php\n\u003c?php\n    // Set user access token\n    Instagram::setAccessToken($accessToken);\n\n    // Get all user likes\n    $likes = Instagram::getUserLikes();\n\n    // Take a look at the API response\n    echo '\u003cpre\u003e';\n    print_r($likes);\n    echo '\u003cpre\u003e';\n?\u003e\n```\n\n# Available methods\n\n## Setup Instagram\n\n`new Instagram($config: Array|String);`\n\n`array` if you want to authenticate a user and access its data:\n\n```php\nnew Instagram([\n    'apiKey'      =\u003e 'YOUR_APP_KEY',\n    'apiSecret'   =\u003e 'YOUR_APP_SECRET',\n    'apiCallback' =\u003e 'YOUR_APP_CALLBACK'\n]);\n```\n\n`string` if you *only* want to access public data:\n\n```php\nnew Instagram('YOUR_APP_KEY');\n```\n\n## Get login URL\n\n`getLoginUrl($scope: [Array], $state: [string])`\n\n```php\ngetLoginUrl(['basic', 'likes'], 'uMFYKG5u6v');\n```\n\n**Optional scope parameters:**\nTo find out more about Scopes, please visit https://www.instagram.com/developer/authorization/\n\n## Get OAuth token\n\n`getOAuthToken($code, \u003ctrue\u003e/\u003cfalse\u003e)`\n\n`true` : Return only the OAuth token\n`false` *[default]* : Returns OAuth token and profile data of the authenticated user\n\n## Set / Get access token\n\nSet access token, for further method calls:\n`setAccessToken($token)`\n\nReturn access token, if you want to store it for later usage:\n`getAccessToken()`\n\n## User methods\n\n- `getUser()`\n- `getUser($id)`\n- `searchUser($name, \u003c$limit\u003e)`\n- `getUserMedia($id, \u003c$limit\u003e)`\n- `getUserLikes(\u003c$limit\u003e)`\n- `getUserMedia(\u003c$id\u003e, \u003c$limit\u003e)`\n    - if an `$id` isn't defined, or equals to `self` it returns the media of the logged in user\n\n\u003e [Sample responses of the User Endpoints.](http://instagram.com/developer/endpoints/users/)\n\n## Relationship methods\n\n- `getSelfFollows()`\n- `getSelfFollowedBy()`\n- `getUserRelationship($id)`\n- `modifyRelationship($action, $user)`\n    - `$action` : Action command (follow / unfollow / block / unblock / approve / deny)\n    - `$user` : Target user id\n\n```php\n\u003c?php\n    // Follow the user with the ID 1574083\n    $instagram-\u003emodifyRelationship('follow', 1574083);\n?\u003e\n```\n\n---\n\nPlease note that the `modifyRelationship()` method requires the `relationships` [scope](#get-login-url).\n\n---\n\n\u003e [Sample responses of the Relationship Endpoints.](http://instagram.com/developer/endpoints/relationships/)\n\n## Media methods\n\n- `getMedia($id)`\n- `searchMedia($lat, $lng, \u003c$distance\u003e, \u003c$minTimestamp\u003e, \u003c$maxTimestamp\u003e)`\n    - `$lat` and `$lng` are coordinates and have to be floats like: `48.145441892290336`,`11.568603515625`\n    - `$distance` Radial distance in meter (default is 1km = 1000, max. is 5km = 5000)\n    - `$minTimestamp` All media returned will be taken *later* than this timestamp (default: 5 days ago)\n    - `$maxTimestamp` All media returned will be taken *earlier* than this timestamp (default: now)\n\n\u003e [Sample responses of the Media Endpoints.](http://instagram.com/developer/endpoints/media/)\n\n## Comment methods\n\n- `getMediaComments($id)`\n- `addMediaComment($id, $text)`\n    - **restricted access:** please email `apidevelopers[at]instagram.com` for access\n- `deleteMediaComment($id, $commentID)`\n    - the comment must be authored by the authenticated user\n\n---\n\nPlease note that the authenticated methods require the `comments` [scope](#get-login-url).\n\n---\n\n\u003e [Sample responses of the Comment Endpoints.](http://instagram.com/developer/endpoints/comments/)\n\n## Tag methods\n\n- `getTag($name)`\n- `getTagMedia($name)`\n- `searchTags($name)`\n\n\u003e [Sample responses of the Tag Endpoints.](http://instagram.com/developer/endpoints/tags/)\n\n## Likes methods\n\n- `getMediaLikes($id)`\n- `likeMedia($id)`\n- `deleteLikedMedia($id)`\n\n\u003e How to like a Media: [Example usage](https://gist.github.com/3287237)\n\u003e [Sample responses of the Likes Endpoints.](http://instagram.com/developer/endpoints/likes/)\n\nAll `\u003c...\u003e` parameters are optional. If the limit is undefined, all available results will be returned.\n\n## Instagram videos\n\nInstagram entries are marked with a `type` attribute (`image` or `video`), that allows you to identify videos.\n\nAn example of how to embed Instagram videos by using [Video.js](http://www.videojs.com), can be found in the `/example` folder.\n\n---\n\n**Please note:** Instagram currently doesn't allow to filter videos.\n\n---\n\n## Signed Requests\n\nIn order to prevent that your access tokens gets stolen, Instagram recommends to sign your requests with a hash of your API secret, the called endpoint and parameters.\n\n1. Activate [\"Enforce Signed Header\"](http://instagram.com/developer/clients/manage/) in your Instagram client settings.\n2. Enable the signed-requests in your Instagram class:\n\n```php\n$instagram-\u003esetEnforceSignedRequests(true);\n```\n\n## Pagination\n\nEach endpoint has a maximum range of results, so increasing the `limit` parameter above the limit won't help (e.g. `getUserMedia()` has a limit of 90).\n\nThat's the point where the \"pagination\" feature comes into play.\nSimply pass an object into the `pagination()` method and receive your next dataset:\n\n```php\n\u003c?php\n    $photos = $instagram-\u003egetTagMedia('kitten');\n\n    $result = $instagram-\u003epagination($photos);\n?\u003e\n```\n\nIteration with `do-while` loop.\n\n## Samples for redirect URLs\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003eRegistered Redirect URI\u003c/th\u003e\n    \u003cth\u003eRedirect URI sent to /authorize\u003c/th\u003e\n    \u003cth\u003eValid?\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003ehttp://yourcallback.com/\u003c/td\u003e\n    \u003ctd\u003ehttp://yourcallback.com/\u003c/td\u003e\n    \u003ctd\u003eyes\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003ehttp://yourcallback.com/\u003c/td\u003e\n    \u003ctd\u003ehttp://yourcallback.com/?this=that\u003c/td\u003e\n    \u003ctd\u003eyes\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003ehttp://yourcallback.com/?this=that\u003c/td\u003e\n    \u003ctd\u003ehttp://yourcallback.com/\u003c/td\u003e\n    \u003ctd\u003eno\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003ehttp://yourcallback.com/?this=that\u003c/td\u003e\n    \u003ctd\u003ehttp://yourcallback.com/?this=that\u0026another=true\u003c/td\u003e\n    \u003ctd\u003eyes\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003ehttp://yourcallback.com/?this=that\u003c/td\u003e\n    \u003ctd\u003ehttp://yourcallback.com/?another=true\u0026this=that\u003c/td\u003e\n    \u003ctd\u003eno\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003ehttp://yourcallback.com/callback\u003c/td\u003e\n    \u003ctd\u003ehttp://yourcallback.com/\u003c/td\u003e\n    \u003ctd\u003eno\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003ehttp://yourcallback.com/callback\u003c/td\u003e\n    \u003ctd\u003ehttp://yourcallback.com/callback/?type=mobile\u003c/td\u003e\n    \u003ctd\u003eyes\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003e If you need further information about an endpoint, take a look at the [Instagram API docs](http://instagram.com/developer/authentication/).\n\n## Example App\n\n![Image](http://cl.ly/image/221T1g3w3u2J/preview.png)\n\nThis example project, located in the `example/` folder, helps you to get started.\nThe code is well documented and takes you through all required steps of the OAuth2 process.\nCredit for the awesome Instagram icons goes to [Ricardo de Zoete Pro](http://dribbble.com/RZDESIGN).\n\n### More examples and tutorials:\n\n- [User likes](https://gist.github.com/cosenary/3287237)\n- [Follow user](https://gist.github.com/cosenary/8322459)\n- [User follower](https://gist.github.com/cosenary/7267139)\n- [Load more button](https://gist.github.com/cosenary/2975779)\n- [User most recent media](https://gist.github.com/cosenary/1711218)\n- [Instagram login](https://gist.github.com/cosenary/8803601)\n- [Instagram signup (9lessons tutorial)](http://www.9lessons.info/2012/05/login-with-instagram-php.html)\n\n\u003e Let me know if you have to share a code example, too.\n\n# Release notes\nYou can find [release notes here](https://github.com/Andreyco/Instagram-for-PHP/releases)\n\n\n# Credits\n\nCopyright (c) 2014 - Andrej Badin\nReleased under the [BSD License](http://www.opensource.org/licenses/bsd-license.php).\n\nInstagram-PHP-API contains code taken from [Christian Metz's](https://github.com/cosenary) [Instagram-PHP-API](https://github.com/cosenary/Instagram-PHP-API), also licensed under [BSD License](COSENARY).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreyco%2Finstagram-for-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreyco%2Finstagram-for-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreyco%2Finstagram-for-php/lists"}