简体   繁体   中英

how to post a comment with instagram API on PHP

i want to ask something about instagram API. i have try this API and get some problem about "Comment" section.

how can i post i comment on instagram API with php curl? on API documentation clearly explain that i must use this code :

curl -F 'access_token=ACCESS-TOKEN' \
 -F 'text=This+is+my+comment' \
 https://api.instagram.com/v1/media/{media-id}/comments

but, i have no idea or a sample for execute this with php. please teach me or give me a sample for using php curl.

any help would be appreciate, thankyou very much :)

update code :

<form method="post" action=''>
<p><em>Media id</em> <input type="text" name="tag" placeholder="Awesome"/><br>
<input type="submit" value="Ok" /></p>
</form>

<?php


  if(!empty($_POST['tag'])){


    $url = 'https://api.instagram.com/v1/media/1285310544400585898_1388393123/comments';

try {
$curl_connection = curl_init($url);
curl_setopt($curl_connection, CURLOPT_POST, true);
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, http_build_query(array('access_token' => 'myaccesstoken','text'=>' test')));
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);

//Data are stored in $data
$data = json_decode(curl_exec($curl_connection), true);
print_r($data);
curl_close($curl_connection);
} catch(Exception $e) {
return $e->getMessage();
}

}
?>

use this function to send a POST request

function httpPost($url, $data)
{
    $curl = curl_init($url);


    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);


    $response = curl_exec($curl);
    curl_close($curl);
    return $response;
}

httpPost('https://api.instagram.com/v1/media/{media-id}/comments', ['access_token' => 'your access token', 'text' => 'your comment'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM