简体   繁体   中英

instagram api, posting a like

I'm working with the instagram API, and unfortunately I've got kind of stuck.
After setting everything up I have a like/dislike button for each instagram image that calls the method below.

vote = function(type, at, mid){
    // type = POST or DELETE
    // at = access_token
    // mid = media_id
    $.ajax({
        type: type,
        dataType: "jsonp",
        crossDomain:true,
        url: "https://api.instagram.com/v1/media/"+mid+"/likes?access_token="+at,
        success: function(data) {
            console.log(data);
        }
    });
}

It returns message(200, OK), suggesting that my like was counted, however neither likes or dislikes are actually counted. Thoughts on what might cause the hiccup?

Cross domain ajax requests can only be type of OPTIONS , if remote HTTP access control is not configured otherwise. And Instagram is not.

So this is will be server-side job. Make that ajax request to your own URL what is going to make request (with CURL probably) to Instagram.

If you don't need response, you can "fake" that request. Make HTML and submit

Try this below code.

var access_token = "https://api.instagram.com/v1/media/"+mid+"/likes?access_token="+at
var url = 
$.post(url, {access_token: access_token},
 function(data) {
   alert("Data Loaded: " + data);
}, "json");

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