doudieheng5322 2016-07-02 10:42
浏览 40
已采纳

如何在PHP上发布带有Instagram API的评论

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();
}

}
?>
  • 写回答

1条回答 默认 最新

  • dongshiru5913 2016-07-02 14:48
    关注

    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'])

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签)
  • ¥50 sft下载大文阻塞卡死