|
1 |
| -# instagram-graph-api-php-sdk |
| 1 | +# instagram-graph-api-php-sdk |
| 2 | + |
| 3 | +This repository contains the open source PHP SDK that allows you to access the Instagram Graph API from your PHP app. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +### Composer |
| 8 | + |
| 9 | +Run this command: |
| 10 | + |
| 11 | +``` |
| 12 | +composer require jstolpe/instagram-graph-api-php-sdk |
| 13 | +``` |
| 14 | + |
| 15 | +Require the the autoloader. |
| 16 | + |
| 17 | +```php |
| 18 | +require_once __DIR__ . '/vendor/autoload.php'; // change path as needed |
| 19 | +``` |
| 20 | + |
| 21 | +### No Composer |
| 22 | + |
| 23 | +Get the repository |
| 24 | + |
| 25 | +``` |
| 26 | +git clone [email protected]:jstolpe/instagram-graph-api-php-sdk.git |
| 27 | +``` |
| 28 | + |
| 29 | +Require the custom autoloader. |
| 30 | + |
| 31 | +```php |
| 32 | +require_once '/instagram-graph-api-php-sdk/src/instagram/autoload.php'; // change path as needed |
| 33 | +``` |
| 34 | + |
| 35 | +## Usage |
| 36 | + |
| 37 | +Simple GET example of a user's profile and media posts. |
| 38 | +```php |
| 39 | +use Instagram\User\BusinessDiscovery; |
| 40 | + |
| 41 | +$config = array( // instantiation config params |
| 42 | + 'user_id' => '<IG_USER_ID>', |
| 43 | + 'username' => '<USERNAME>', // string of the Instagram account username to get data on |
| 44 | + 'access_token' => '<ACCESS_TOKEN>', |
| 45 | +); |
| 46 | + |
| 47 | +// instantiate business discovery for a user |
| 48 | +$businessDiscovery = new BusinessDiscovery( $config ); |
| 49 | + |
| 50 | +// initial business discovery |
| 51 | +$userBusinessDiscovery = $businessDiscovery->getSelf(); |
| 52 | +``` |
| 53 | + |
| 54 | +Simple POST example of posting an image to an Instagram account. |
| 55 | +```php |
| 56 | +use Instagram\User\Media; |
| 57 | +use Instagram\User\MediaPublish; |
| 58 | + |
| 59 | +$config = array( // instantiation config params |
| 60 | + 'user_id' => '<USER_ID>', |
| 61 | + 'access_token' => '<ACCESS_TOKEN>', |
| 62 | +); |
| 63 | + |
| 64 | +// instantiate user media |
| 65 | +$media = new Media( $config ); |
| 66 | + |
| 67 | +$imageContainerParams = array( // container parameters for the image post |
| 68 | + 'caption' => '<CAPTION>', // caption for the post |
| 69 | + 'image_url' => '<IMAGE_URL>', // url to the image must be on a public server |
| 70 | +); |
| 71 | + |
| 72 | +// create image container |
| 73 | +$imageContainer = $media->create( $imageContainerParams ); |
| 74 | + |
| 75 | +// get id of the image container |
| 76 | +$imageContainerId = $imageContainer['id']; |
| 77 | + |
| 78 | +// instantiate media publish |
| 79 | +$mediaPublish = new MediaPublish( $config ); |
| 80 | + |
| 81 | +// post our container with its contents to instagram |
| 82 | +$publishedPost = $mediaPublish->create( $imageContainerId ); |
| 83 | +``` |
| 84 | + |
| 85 | +Example of a custom request. |
| 86 | +```php |
| 87 | +// first we have to instantiate the core Instagram class with our access token |
| 88 | +$instagram = new Instagram\Instagram( array( |
| 89 | + 'access_token' => '<ACCESS_TOKEN>' |
| 90 | +) ); |
| 91 | + |
| 92 | +/** |
| 93 | + * Here we are making our request to instagram and specify the endpoint along with our custom params. |
| 94 | + * There is a custom function for get, post, and delete. |
| 95 | + * $instagram->get() |
| 96 | + * $instagram->post() |
| 97 | + * $instagram->delete() |
| 98 | + * |
| 99 | + * Here is the skeleton for the customized call. |
| 100 | + */ |
| 101 | +$response = $instagram->method( array( |
| 102 | + 'endpoint' => '/<ENDPOINT>', |
| 103 | + 'params' => array( // query params key/values must match what IG API is expecting for the endpoint |
| 104 | + '<KEY>' => '<VALUE>', |
| 105 | + '<KEY>' => '<VALUE>', |
| 106 | + // ... |
| 107 | + ) |
| 108 | +) ); |
| 109 | +``` |
| 110 | + |
| 111 | +## Documentation |
| 112 | + |
| 113 | +See the [Wiki](https://github.com/jstolpe/instagram-graph-api-php-sdk/wiki) for the complete documentation. |
0 commit comments