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

如何在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 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)