-
Notifications
You must be signed in to change notification settings - Fork 60
/
example.php
43 lines (40 loc) · 1.49 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* Instagram PHP API example usage.
* This is the entry point of your application, it will detect whether
* the user is already authenticated and will present her the login
* window in case she is not.
*
* If the authentication token is already stored (as a cookie in this case),
* the user will be redirected to callback.php which is basically the same
* URI callback that you must set up with Instagram as the return address
* for your application on their developers section:
* http://instagr.am/developer/
*
*
* If you have any question, check http://mauriciocuenca.com/ for the
* latest updates
*/
require_once 'Instagram.php';
/**
* Configuration params, make sure to write exactly the ones
* instagram provide you at http://instagr.am/developer/
*/
$config = array(
'client_id' => 'e8d6b06f7550461e897b45b02d84c23e',
'client_secret' => '2357fc69da344800acef2592ef647491',
'grant_type' => 'authorization_code',
'redirect_uri' => 'http://mauriciocuenca.com/qnktwit/confirm.php',
);
/**
* This is how a wrong response looks like
* array(1) { ["InstagramOAuthToken"]=> string(89) "{"code": 400, "error_type": "OAuthException", "error_message": "No matching code found."}" }
*/
session_start();
if (isset($_SESSION['InstagramAccessToken']) && !empty($_SESSION['InstagramAccessToken'])) {
header('Location: callback.php');
die();
}
// Instantiate the API handler object
$instagram = new Instagram($config);
$instagram->openAuthorizationUrl();