forked from aseba/php-instagram-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpirt.php
More file actions
76 lines (67 loc) · 2.41 KB
/
phpirt.php
File metadata and controls
76 lines (67 loc) · 2.41 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
require 'curl/curl.php';
class InstagramRealTime {
private $settings = array();
private $base_url = 'https://api.instagram.com/v1';
private $signature;
public function InstagramRealTime($client_id, $client_secret, $callback_url=null){
$this->settings = array(
'client_id' => $client_id,
'client_secret' => $client_secret
);
if(!is_null($callback_url)){
$this->settings['callback_url'] = $callback_url;
}
}
public function addSignature($ip) {
if (empty($this->settings['client_secret'])) {
throw new Exception('Can not sign the request without OAuth Client Secret');
}
$this->signature = $ip .'|'. hash_hmac('sha256', $ip, $this->settings['client_secret'], false);
}
public function addSubscription($object, $aspect, $object_id=null, $extra=array()){
$params = array_merge($this->settings, array(
'object' => $object,
'aspect' => $aspect
));
if(!is_null($object_id)) $params['object_id'] = $object_id;
foreach($extra as $extraKey=>$extraValue){
$params[$extraKey] = $extraValue;
}
return $this->generic("/subscriptions/", $params);
}
public function listSubscriptions(){
return $this->generic("/subscriptions/");
}
public function deleteSubscription($object=null, $id=null){
if(is_null($object) and is_null($id)) throw new Exception("You must set and object type or and object id. If you want to delete all set object as 'all'");
elseif(!is_null($object) and is_null($id)) {
$params = array_merge($this->settings, array(
'object' => $object
));
}
elseif(is_null($object) and !is_null($id)) {
$params = array_merge($this->settings, array(
'id' => $id
));
}
else throw new Exception("You must set and object type or and object id, not both");
$curl = new Curl;
// This is done because it seems instagram does not accept params correctly (or something). We got to send them in the url
$params = http_build_query($params, '', '&');
$url = $this->base_url . '/subscriptions?' . $params;
return(json_decode($curl->delete($url, $params), true));
}
public function generic($endpoint='', $params=array()){
$curl = new Curl;
if (!is_null($this->signature)) {
$curl->headers['X-Insta-Forwarded-For'] = $this->signature;
}
$params = array_merge( $this->settings, $params );
$url = $this->base_url . $endpoint;
return(json_decode($curl->get($url, $params), true));
}
}
class SubscriptionProcessor{
public static function process($data){}
}