APISubscriptionError instagram API private network - node.js

I'm trying set up a instagram subscription on my localhost with the Instagram-node nodeJs API, but when I launch this code I got this error :
{ [Error: APISubscriptionError: Invalid URL. The URL may be on a private network.]
code: 400,
error_type: 'APISubscriptionError',
error_message: 'Invalid URL. The URL may be on a private network.',
retry: [Function] } undefined
the code :
var express = require('express');
var app = express();
var api = require('instagram-node').instagram();
api.use({access_token : 'xxxxxxxxxxxxxxx'})
api.use({
client_id:'xxxxxxxxxx',
client_secret:'xxxxxxxxxxxxx'
});
var redirect_uri = 'http://127.0.0.1:3000/callback';
api.add_geography_subscription(48.565464564, 2.34656589, 100, 'http://127.0.0.1:3000/callback',
{},
function(err, result, remaining, limit){
console.log(err,result)
});
app.listen(3000);
Any ideas ?

Instagram or anybody esle cannot access your localhost or 127.0.0.1 as this IP address is just known and accessible on your computer itself.
You have to register the callback on a public IP address or domain and host your application there.

I am currently building an app using NodeJS and Instagram Real-time API myself. The answer to this is to use something like http://localtunnel.me/. You could also host your app on something like Heroku as well.
The marked answer is only partially correct.

Related

Nodejs Fetch API: unable to verify the first certificate

I'm using the fetch API module in my Philips Hue project and when I make a call to the local ip address (my hub) it produces that error in the title.
const fetch = require('node-fetch');
const gateway = "192.168.0.12";
const username = "username";
let getLights = function(){
fetch(`https://${gateway}/api/${username}/lights`, {
method: 'GET'
}).then((res) => {
return res.json();
}).then((json) => {
console.log(json);
});
}
module.exports = {getLights};
Any SECURE fix this will eventually go onto the public internet for me to access my lights from anywhere sooo?
To skip the SSL tests, you can use this:
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;
It seems like you tried to access it using HTTPS. Most likely on your local network it is going to be HTTP
So by changing https://${gateway}/api/${username}/lights to http://${gateway}/api/${username}/lights should work.
If you're trying to keep it HTTPS then you will have to install a SSL certificate authority onto your network.
These may be useful sources if you're trying to get that done:
https://www.freecodecamp.org/news/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec/
https://letsencrypt.org/docs/certificates-for-localhost/

SendTransaction API Creation For Bitcoin

I'm facing issue on creating sendtransaction API using bitcore SendFrom method here please lookup my API ("http://localhost:3000/bitcoin/api/sendfrom?"""2NFuJDmdvKWP2zB5EfsXqNuYz9AW65tBrAy" 0.001 6 "donation" "seans outpost"") and its getting like "error:A wallet phrase needed and has not set" Anyone can please tell me how to create sendtrasaction API for bitcoin using nodejs and bitcore already i created generateNewaddress and getbalance,getaccounts API's i tested it in postman. please find below nodejs code:
var bitcoinapi = require('bitcoin-node-api');
var express = require('express');
var app = express();
var port =3000;
//Username and password relate to those set in the bitcoin.conf file
var wallet = {
host: 'localhost',
port: 18332,
user: 'test',
pass: 'test123'
};
bitcoinapi.setWalletDetails(wallet);
bitcoinapi.setAccess('default-safe'); //Access control
app.use('/bitcoin/api', bitcoinapi.app); //Bind the middleware to any chosen url
app.listen(3000);
console.log('server is running at port ' +port);
please find below screens:
Did you install and setup BitcoinCore?
You need to run the deamon in BitcoinCore (your "wallet" settings)
Btw. you can use the api of the deamon directly (it's not anymore up to date, but gives you an idea: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list )

Can't access NodeJS api from Angular app

I have trouble trying to get to my NodeJs server from my angular app. Here's my router:
app.get('/new12345',function(req,res){
console.log("Http Get Recently Gone from /new12345");
var results = userData;
res.send(results);
});
Here where I try getting to my api.
this.http.get('/new12345').subscribe(data => {
this.resultInArray = data['results'];
}
I am getting this error though:
Error: Cannot match any routes. URL Segment: 'new12345'
Thanks!
You did not specify your api base url. You are currently getting to your angular app (hence the angular router error you are getting).
For example, that might look like this:
this.http.get('http://localhost:3000/new12345').subscribe(data => {
this.resultInArray = data['results'];
}

nodejs app is not able to connect to REST api nodejs app

I have a nodejs REST api hosted on localhost and I have a nodejs app that is consuming it. This app too is running on localhost. Everything was working fine but after a restart the webapp just could not connect to the REST api anymore. I am running Windows 10.
I tested the REST api with postman and also with browser, it worked. There is no issue with the REST api.
Tried changing the port numbers - same result.
I ran wireshark to see the difference between when requesting from browser and from nodejs webapp. Below is the screenshot. First two lines are when the nodejs app made the request and the next two are from browser.
I am not able to understand what is wrong here. I tried with a standalone nodejs script, that too failed. Below is the script I used.
var request = require('request');
var u = "xxx";
var p = "xxx";
var auth = "Basic " + new Buffer(u + ":" + p).toString("base64");
var username = "qqqq";
var password = "eeee";
var options = {
url : 'http://localhost:4001/api/v1/transaction',
headers : {
"Authorization" : auth
},
};
console.log(options.url);
request.get(options, function(error,response,body){
//console.log(options);
//console.log(response);
console.log(response.statusCode);
console.log(body);
if (!error && response.statusCode == 200) {
var userObj = JSON.parse(body);
callback(userObj);
} else {
console.log("---- Error ----")
console.log(error);
}
});
I have found the problem and I am posting the answer in the hope that someone would find it useful.
My hint was from the wireshark. (screenshot in the question) All successful requests went to [::1] not localhost or 127.0.0.1. After the reboot of the windows 10 machine, the REST api nodejs app was actually no longer serving on the ip v4 localhost but was serving on ip v6 localhost. There was absolutely no issue with the code.
Instead of using localhost in the url in the consuming webapp, I changed it to [::1] and it started to work.
.....
.....
var options = {
//url : 'http://localhost:4001/api/v1/transaction',
// replaced localhost with [::1]
url : 'http://[::1]:4001/api/v1/transaction',
headers : {
"Authorization" : auth
},
};
.....
.....

Returning 401 error for all routes with hapijs

We're using Hapi JS for our rest server. We store the authentication tokens for the users on Redis. Now, if for some reason node loses connection with Redis, we need to return 401 Authorization failed error to all the clients from all the routes so the clients can logout automatically.
So, is there a way to return 401 from all routes without changing the code in the route handler functions?
You can make use of the Hapi server extension event 'onRequest'.
var hapi = require('hapi');
var Boom = require('boom');
var server = new hapi.Server();
//Configure your server
//Add an extension point
server.ext('onRequest', function (request, reply) {
var status;
//Check status of redis instance
if (status) {
//Redis is running, continue to handler
return reply.continue();
} else {
//Redis is down, reply with error
return reply(Boom.unauthorized('Auth server is down'));
}
});
This is probably not how you will verify the status your redis instance, but I hope you get the point.
One can look up various other extension points here.
You should do this in the auth plugin used by your app. Take a look at the hapi-auth-basic implementation: https://github.com/hapijs/hapi-auth-basic/blob/master/lib/index.js
If you look in the scheme you must define an authenticate method which takes the request and reply. This is where you should check redis for an auth token. If the connection is not available you should
return reply(Boom.unauthorized('Authorization failed', 'Basic'));
Hope this helps.

Resources