如何发布像阿贾克斯到Instagram的?请帮帮我帮帮我、像阿贾克斯到、Instagram

2023-09-11 01:33:14 作者:陌语

我有这个code,但它不工作。它说,我的AJAX职位是成功的,但是当我看到使刷新我看到了它的不喜欢。

 &LT ;?
如果($数据 - > user_has_liked ==假)
{
?>

< A HREF =#ID =< = $数据 - > ID;>中类=喜欢和GT;<跨度类=< = $数据 - > ID;>中>像< / SPAN>< / A>
&LT ;? }其他{回声'顶过'; ?}>

<脚本类型=文/ JavaScript的>
       $('a.like)。点击(函数(){
            VAR mediaId = $(本).attr('身份证');
            $阿贾克斯({
                网址:https://api.instagram.com/v1/media/+ mediaId +??/喜欢回调=,
                数据类型:JSONP
                数据: {
                    access_token:'?< = $ access_token;>',
                    _method:POST
                },
                键入:POST,
                成功:功能(数据,textStatus,jqXHR){
                  $(+ mediaId +。)文本('喜欢以下')。
                },
                错误:函数(jqXHR,textStatus,errorThrown){
                     $(+ mediaId +。)的文本。('错误&所述峰; br />!'+ textStatus +' - '+ errorThrown);
               }
             });
        });
< / SCRIPT>
 

解决方案

我建立类似的东西,最近也遇到了这个问题。

即使你的请求被发送作为类型:职位本身实际发送的GET请求。这将导致您的请求返回成功不喜欢什么。相反,它会返回所有数据,这些介质ID。

如果你改变你的数据类型为JSON,而不是JSONP您请求应该如你所愿;但是,它可能需要一个HTTPS连接需要一个SSL。

阿贾克斯全队合影阿莱22号球衣表达支持 我们与你同在

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>

解决方案

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.