Skip to content

Commit 4407700

Browse files
committed
initial commit
1 parent 9bc4b5a commit 4407700

37 files changed

+7084
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#-------------------------
2+
# Composer
3+
#-------------------------
4+
vendor/
5+
composer.lock

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "jstolpe/instagram-graph-api-php-sdk",
3+
"description": "Instagram Graph API PHP SDK",
4+
"keywords": ["instagram", "api", "graph api", "sdk", "php", "instagram graph api"],
5+
"type": "library",
6+
"homepage": "https://github.com/jstolpe/instagram-graph-api-php-sdk",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Justin Stolpe",
11+
"homepage": "https://github.com/jstolpe/instagram-graph-api-php-sdk"
12+
}
13+
],
14+
"require": {
15+
"php": "^5.6|^7.0"
16+
},
17+
"autoload": {
18+
"psr-4": {
19+
"Instagram\\": "src/Instagram/"
20+
}
21+
}
22+
}

src/Instagram/Comment/Comment.php

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2022 Justin Stolpe.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
namespace Instagram\Comment;
25+
26+
// other classes we need to use
27+
use Instagram\Instagram;
28+
use Instagram\Request\Params;
29+
use Instagram\Request\Fields;
30+
31+
/**
32+
* Comment
33+
*
34+
* Get comments on a specific media.
35+
* - Endpoint Format: GET /{ig-comment-id}?fields={fields}&access_token={access-token}
36+
* - Endpoint Format: POST /{ig-comment-id}?hide={hide}&access_token={access-token}
37+
* - Endpoint Format: DELETE /{ig-comment-id}?access_token={access-token}
38+
* - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-comment
39+
*
40+
* @package instagram-graph-api
41+
* @author Justin Stolpe
42+
* @link https://github.com/jstolpe/instagram-graph-api
43+
* @license https://opensource.org/licenses/MIT
44+
* @version 1.0
45+
*/
46+
class Comment extends Instagram {
47+
/**
48+
* @var integer $commentId Instagram id of the comment.
49+
*/
50+
protected $commentId;
51+
52+
/**
53+
* Contructor for instantiating a new object.
54+
*
55+
* @param array $config for the class.
56+
* @return void
57+
*/
58+
public function __construct( $config ) {
59+
// call parent for setup
60+
parent::__construct( $config );
61+
62+
// store the user id
63+
$this->commentId = $config['comment_id'];
64+
}
65+
66+
/**
67+
* Get a comment.
68+
*
69+
* @param array $params params for the GET request.
70+
* @return Instagram response.
71+
*/
72+
public function getSelf( $params = array() ) {
73+
$getParams = array( // parameters for our endpoint
74+
'endpoint' => '/' . $this->commentId,
75+
'params' => $this->getParams( $params )
76+
);
77+
78+
// ig get request
79+
$response = $this->get( $getParams );
80+
81+
// return response
82+
return $response;
83+
}
84+
85+
/**
86+
* Get params for the request.
87+
*
88+
* @param array $params specific params for the request.
89+
* @return array of params for the request.
90+
*/
91+
public function getParams( $params = array() ) {
92+
if ( $params ) { // specific params have been requested
93+
return $params;
94+
} else { // get all params
95+
// get field params
96+
$params[Params::FIELDS] = Fields::getDefaultCommentFields() . ',' .
97+
Fields::REPLIES . '{' .
98+
Fields::getDefaultCommentFields() .
99+
'}'
100+
;
101+
102+
// return our params
103+
return $params;
104+
}
105+
}
106+
107+
/**
108+
* Set hide parameter on a comment.
109+
*
110+
* @param boolean $hide show or hide the comment with true|false.
111+
* @return Instagram Response.
112+
*/
113+
public function setHide( $hide ) {
114+
$postParams = array( // parameters for our endpoint
115+
'endpoint' => '/' . $this->commentId,
116+
'params' => array(
117+
Params::HIDE => $hide
118+
)
119+
);
120+
121+
// ig get request
122+
$response = $this->post( $postParams );
123+
124+
// return response
125+
return $response;
126+
}
127+
128+
/**
129+
* Delete a comment.
130+
*
131+
* @return Instagram Response.
132+
*/
133+
public function remove() {
134+
$postParams = array( // parameters for our endpoint
135+
'endpoint' => '/' . $this->commentId
136+
);
137+
138+
// ig get request
139+
$response = $this->delete( $postParams );
140+
141+
// return response
142+
return $response;
143+
}
144+
}
145+
146+
?>

src/Instagram/Comment/Replies.php

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2022 Justin Stolpe.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
namespace Instagram\Comment;
25+
26+
// other classes we need to use
27+
use Instagram\Instagram;
28+
use Instagram\Request\Params;
29+
use Instagram\Request\Fields;
30+
31+
/**
32+
* Replies
33+
*
34+
* Replies on a specific media.
35+
* - Endpoint Format: GET /{ig-comment-id}/replies?fields={fields}&access_token={access-token}
36+
* - Endpoint Format: POST /{ig-comment-id}/replies?message={message}&access_token={access-token}
37+
* - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-comment/replies
38+
*
39+
* @package instagram-graph-api
40+
* @author Justin Stolpe
41+
* @link https://github.com/jstolpe/instagram-graph-api
42+
* @license https://opensource.org/licenses/MIT
43+
* @version 1.0
44+
*/
45+
class Replies extends Comment {
46+
/**
47+
* @const Instagram endpoint for the request.
48+
*/
49+
const ENDPOINT = 'replies';
50+
51+
/**
52+
* Contructor for instantiating a new object.
53+
*
54+
* @param array $config for the class.
55+
* @return void
56+
*/
57+
public function __construct( $config ) {
58+
// call parent for setup
59+
parent::__construct( $config );
60+
}
61+
62+
/**
63+
* Create a reply on a comment.
64+
*
65+
* @param string $message reply to post.
66+
* @return Instagram Response.
67+
*/
68+
public function create( $message ) {
69+
$postParams = array( // parameters for our endpoint
70+
'endpoint' => '/' . $this->commentId . '/' . self::ENDPOINT,
71+
'params' => array(
72+
Params::MESSAGE => $message
73+
)
74+
);
75+
76+
// ig get request
77+
$response = $this->post( $postParams );
78+
79+
// return response
80+
return $response;
81+
}
82+
83+
/**
84+
* Get replies for a comment.
85+
*
86+
* @param array $paramsparams for the GET request.
87+
* @return Instagram response.
88+
*/
89+
public function getSelf( $params = array() ) {
90+
$getParams = array( // parameters for our endpoint
91+
'endpoint' => '/' . $this->commentId . '/' . $this->endpoint,
92+
'params' => $params ? $params : Params::getFieldsParam( Fields::getDefaultCommentFields( false ) )
93+
);
94+
95+
// ig get request
96+
$response = $this->get( $getParams );
97+
98+
// return response
99+
return $response;
100+
}
101+
}
102+
103+
?>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2022 Justin Stolpe.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
namespace Instagram\Container;
25+
26+
// other classes we need to use
27+
use Instagram\Instagram;
28+
use Instagram\Request\Params;
29+
use Instagram\Request\Fields;
30+
31+
/**
32+
* Container
33+
*
34+
* Get info on a container.
35+
* - Endpoint Format: GET /{ig-container-id}/?fields={fields}&access_token={access-token}
36+
* - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-container
37+
*
38+
* @package instagram-graph-api
39+
* @author Justin Stolpe
40+
* @link https://github.com/jstolpe/instagram-graph-api
41+
* @license https://opensource.org/licenses/MIT
42+
* @version 1.0
43+
*/
44+
class Container extends Instagram {
45+
/**
46+
* @var integer $containerId Instagram container id for publishing media.
47+
*/
48+
protected $containerId;
49+
50+
/**
51+
* @var array $fields a list of all the fields we are requesting to get back.
52+
*/
53+
protected $fields = array(
54+
Fields::ID,
55+
Fields::STATUS,
56+
Fields::STATUS_CODE
57+
);
58+
59+
/**
60+
* Contructor for instantiating a new object.
61+
*
62+
* @param array $config for the class.
63+
* @return void
64+
*/
65+
public function __construct( $config ) {
66+
// call parent for setup
67+
parent::__construct( $config );
68+
69+
// store the user id
70+
$this->containerId = $config['container_id'];
71+
}
72+
73+
/**
74+
* Get the status of a container.
75+
*
76+
* @param array $params params for the GET request.
77+
* @return Instagram response.
78+
*/
79+
public function getSelf( $params = array() ) {
80+
$getParams = array( // parameters for our endpoint
81+
'endpoint' => '/' . $this->containerId,
82+
'params' => $params ? $params : Params::getFieldsParam( $this->fields )
83+
);
84+
85+
// ig get request
86+
$response = $this->get( $getParams );
87+
88+
// return response
89+
return $response;
90+
}
91+
}
92+
93+
?>

0 commit comments

Comments
 (0)