How to post like with ajax to instagram? Help me please

孤街浪徒 提交于 2019-12-11 05:28:26

问题


i have this code but its not working. it says to me ajax post is success but when i look make refresh i saw its not liked.

<?
if ($data->user_has_liked == false) 
{ 
?>

<a href="#" id="<?=$data->id;?>" class="like"><span class="<?=$data->id;?>">Like</span></a>
<? } else { echo 'Liked'; } ?>

<script type="text/javascript">
       $('a.like').click(function() {
            var mediaId = $(this).attr('id');
            $.ajax({
                url: "https://api.instagram.com/v1/media/" + mediaId + "/likes?callback=?",
                dataType: "jsonp",
                data: {
                    access_token: '<?=$access_token;?>',
                    _method: 'POST'
                },
                type: "POST",
                success: function(data, textStatus, jqXHR) {
                  $("."+mediaId+"").text('Liked');
                },
                error: function(jqXHR, textStatus, errorThrown) {
                     $("."+mediaId+"").text('Error!<br/>' + textStatus + ' - ' + errorThrown);
               }
             });
        });
</script>

回答1:


I am building something similar and have ran into this problem recently.

Even though your request is sent as a type: POST the request itself is actually sent as GET. This causes your request to return successful without liking anything. Instead it will return all the data for that Media ID.

If you change your datatype to JSON instead of JSONP you request should work as you wish; however, it may require an HTTPS connection requiring an SSL.



来源:https://stackoverflow.com/questions/11703011/how-to-post-like-with-ajax-to-instagram-help-me-please

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!