Search code examples
node.jsinstagraminstagram-api

nodejs and instagram-node i am getting a 400 - Unable to reach callback URL


I have seen instagram-api-unable-to-reach-callback-url. This does not help. I am trying to subscribe a user

The Authorize works fine and it calls my callback successfully (redirect_uri = http://home.mydomain.me:8889/handleauth) and I get a result.access_token

exports.handleauth = function(req, res) {
    api.authorize_user(req.query.code, redirect_uri, function(err, result) {
     if (err) {
        console.log(err.body);
        res.send("Didn't work");
     } else {
        console.log('Yay! Access token is ' + result.access_token);
        res.send('You made it!!');
     }
   });
};

but when i try the subscription call, i get

{"code":400,"error_type":"APISubscriptionError","error_message":"Unable to reach callback URL \"http://home.mydomain.me:8889/newpost\"."}

exports.subscribe2= function(req, res, next) {

var headers = {
    'User-Agent':       'Super Agent/0.0.1',
    'Content-Type':     'application/x-www-form-urlencoded'
}
var options = {
    url: 'https://api.instagram.com/v1/subscriptions/',
    method: 'POST',
    headers: headers,
    form: {'client_id': 'myclientid'
            , 'client_secret': 'myclientsecret'
            , 'object': 'user'
            , 'aspect': 'media'
            , 'verify_token': myAccessToken from result.access_token above
            , 'callback_url': 'http://home.mydomain.me:8889/newpost'
          }
};

request(options, function (error, response, body) {
    if (!error && response.statusCode == 200) {
        // Print out the response body
        console.log(body)
        res.send(body);
    } else{
        console.log(error)
        res.send(body);
    }
})

};

I know the URL it is available. I can go to http://home.mydomain.me:8889/newpost via my browser. I also accessed the URL from https://www.site24x7.com/check-website-availability.html

Thanks for any help / suggestions


Solution

  • The way i got this work was to make my callback use https instead of http