This is my code run on a node.js server. I have the proper access token obtained from OAuth2.0 protocol as defined in the Instagram developer page.
function getMedia(accessToken) {
var instagram = require('instagram-node').instagram();
instagram.use({
access_token: accessToken
});
instagram.user_self_media_recent(function(err, medias, pagination, remaining, limit) {
if(err) {
console.log(err);
}
console.log(medias);
});
}
I'm getting this in my error response:
{ Error: getaddrinfo ENOTFOUND api.instagram.com api.instagram.com:443
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'api.instagram.com',
host: 'api.instagram.com',
port: 443,
retry: [Function: retry] }
Does anyone know what this error response means?
Quick follow up. I was using Google's Firebase for my backend. On the "Spark" plan you get this warning:
Billing account not configured. External network is not accessible and
quotas are severely limited. Configure billing account to remove these
restrictions
I upgraded to "Blaze" plan and now retrieve data from Instagram.
The answer posted below suggests that I need to initialize the Instagram client with a client_id and client_secret, this is not true. I am getting media posts with just the access_token.
Thanks
When you initialize the instagram client you should use your app's client Id and client secret.
instagram.use({
client_id: INSTA_CLIENT_ID,
client_secret: INSTA_CLIENT_SECRET,
});
Then use the access token you have to authenticate the specific instagram user and request medias on their behalf.
instagram.use({
access_token: accessToken
});
instagram.user_self_media_recent(function(err, medias, pagination, remaining, limit) {
if(err) {
console.log(err);
}
console.log(medias);
});
When you first initialize your instagram node client you must use the authentication credentials that you receive from instagram when you register your app here.
Related
const Twitter = require('twitter');
const client = new Twitter({
consumer_key: 'XXXX',
consumer_secret: 'XXXX',
access_token_key: 'XXXX',
access_token_secret: 'XXXX'
});
client.post('statuses/update', {status: 'Posting via the Node is awesome!'}, function(
error,
tweet,
response
) {
if (error) throw error;
// console.log(tweet); // Tweet body.
// console.log(response); // Raw response object.
});
Please Find Below the error:
if (error) throw error;
^
Error: getaddrinfo ENOTFOUND api.twitter.com api.twitter.com:443
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)
Note : I was trying to hit the twitter api using the firewall application proxy. Actually by default api.twitter.com was blocked by firewall but I requested from env team to add the api.twitter.com in proxy application Link list and they added. Still I am getting the below error any idea how i can check this what is happening and how to solve this.
I'm trying to start a Vault service in my NodeJS app.
Using CLI to use Vault is ok,
but i need it to work automatically when the app is started.
I try this
async started(ctx) {
var options = {
apiVersion: 'v1', // default
endpoint: 'http://127.0.0.1:8500', // default
};
// get new instance of the client
var vault = require("node-vault")(options);
// init vault server
vault.init({ secret_shares: 1, secret_threshold: 1 })
.then( (result) => {
var keys = result.keys;
// set token for all following requests
vault.token = result.root_token;
// unseal vault server
return vault.unseal({ secret_shares: 1, key: keys[0] })
})
.catch(console.error);
// see if it is ok
vault.status()
.then (res => {
console.log('STATuuuuuuuuuuusS', res);
})
.catch((err) => {
console.log("errrrrrreur status");
console.error(err.message);
});
But i've got this error:
RequestError: Error: connect ECONNREFUSED 127.0.0.1:8500
[...]
cause: Error: connect ECONNREFUSED 127.0.0.1:8500
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 8500
},
If i run this before, it worked
vault server -config=config.hcl
Even when i kill it, it seems to work without reloading it. I'm missing something here, for sure :)
I'm wondering if node-vault should start Vault server ? If not, i'm wondering how to start the Vault server from the app and not the CLI ?
If you know the good way to do it, or have clues, i'm all ears.
Nicolas
No, usually the code shouldn't start the server.
Yes, your code is working correctly. If you have not started the server, the error means that it is impossible to connect to the specified IP address and port, they are closed.
The vault server has nothing to do with it, the same behavior will be the database server or any other.
I'm trying to set up the admin sdk and also created a new private key. I even reverted back to an old version with only the admin sdk and it won't work. Is there anything which could be cached on my device?
Nest application successfully started NestApplication true
Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND". Error: Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND".
at FirebaseAppError.FirebaseError [as constructor] (/Users/user/Documents/Dev/project/demo/node_modules/firebase-admin/lib/utils/error.js:42:28)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (/Users/user/Documents/Dev/project/demo/node_modules/firebase-admin/lib/utils/error.js:88:28)
at new FirebaseAppError (/Users/user/Documents/Dev/project/demo/node_modules/firebase-admin/lib/utils/error.js:122:28)
at /Users/user/Documents/Dev/project/demo/node_modules/firebase-admin/lib/firebase-app.js:121:23
at processTicksAndRejections (internal/process/task_queues.js:85:5)
at /Users/user/Documents/Dev/project/demo/node_modules/#nestjs/core/router/router-execution-context.js:44:28
at /Users/user/Documents/Dev/project/demo/node_modules/#nestjs/core/router/router-proxy.js:8:17 ExceptionsHandler
This is how I'm trying to use both packages:
import * as firebase from 'firebase-admin';
import * as serviceAccount from '../../firebase_credentials.json';
const config = {
type: serviceAccount.type,
projectId: serviceAccount.project_id,
privateKeyId: serviceAccount.private_key_id,
privateKey: serviceAccount.private_key,
clientEmail: serviceAccount.client_email,
clientId: serviceAccount.client_id,
authUri: serviceAccount.auth_uri,
tokenUri: serviceAccount.token_uri,
authProviderX509CertUrl: serviceAccount.auth_provider_x509_cert_url,
clientC509CertUrl: serviceAccount.client_x509_cert_url,
};
if (!firebase.apps.length) {
firebase.initializeApp(config);
}
export const firebaseAuth = firebase.auth();
export function create(email: string, password: string) {
firebaseAuth.createUser({
email: email,
emailVerified: false,
password: password,
displayName: email,
disabled: false,
})
.then( (userRecord) => {
// See the UserRecord reference doc for the contents of userRecord.
console.log('Successfully created new user:', userRecord.uid);
})
.catch((error) => {
console.log('Error creating new user:', error);
});
}
What should I try to get this resolved?
Thanks for any help
You can't use both the Admin SDK and the regular Firebase JavaScript SDK in a single application. If the app runs in a potentially untrusted environment, you should use the regular JavaScript SDK. If it runs in a trusted environment (such as your development machine, a server you control, or Cloud Functions) you can use either the JavaScript SDK or the Admin SDK for that environment (in your case for Node.js).
Code:
var rp = require('request-promise');
var options = {
method: 'POST',
uri: 'http://c663fe13.ngrok.io/ap/lighton',
body: {"color": 'white'},
json: true // Automatically stringifies the body to JSON
};
rp(options)
.then(function (parsedBody) {
// POST succeeded...+
console.log("parsedBody", parsedBody);
})
.catch(function (err) {
// POST failed...
console.log("err", err);
});
but this gives me the following error:
{ RequestError: Error: getaddrinfo EAI_AGAIN c663fe13.ngrok.io:80
at new RequestError (/srv/node_modules/request-promise-core/lib/errors.js:14:15)
at Request.plumbing.callback (/srv/node_modules/request-promise-core/lib/plumbing.js:87:29)
at Request.RP$callback [as _callback] (/srv/node_modules/request-promise-core/lib/plumbing.js:46:31)
. . .
name: 'RequestError', message: 'Error: getaddrinfo EAI_AGAIN
c663fe13.ngrok.io:80',
cause: { Error: getaddrinfo EAI_AGAIN
c663fe13.ngrok.io:80
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
errno: 'EAI_AGAIN',
code: 'EAI_AGAIN',
syscall: 'getaddrinfo',
hostname: 'c663fe13.ngrok.io',
host: 'c663fe13.ngrok.io',
port: 80 },
I trie to call that API with postman and it's working fine.
If you are using a free account you will not be able to hit any 3rd party services from Firebase cloud functions. It would be better if you write down your own webhook code and using fulfillment integrate that webhook with your Dialogflow agent if you are going to use the free account.
UPDATE
Check out the code snippets I have shared here. You can use that to integrate ExpressJS and then add your POST code and host it locally. Expose the local server using ngrok and then put that URL in fulfillment.
I am writing a Node.js app and am trying to integrate an ADFS server to get authentication. For that, I am using wstrust-client, and using the ADFS Server URL as my endpoint. My code so far is:
app.get('/login', function(req, res) {
trustClient.requestSecurityToken({
scope: 'https://mycompany.com',
username: "username",
password: "password",
endpoint: 'https://[adfs server]/adfs/services/trust/13/usernamemixed'
}, function (rstr) {
// Access the token
var rawToken = rstr.token;
console.log('raw: ' + rawToken);
}, function(error) {
console.log(error)
});
});
I am requesting https through wstrust-client
My code in wstrustclient.js so far is:
var req = https.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function(data) {
console.log("Entered res")
var rstr = {
token: parseRstr(data),
response: res,
};
callback(rstr);
});
});
req.write(message);
req.end();
req.on('error', function (e) {
console.log("******************************");
console.log(e);
console.log("******************************");
However, it is throwing this error:
******************************
{ [Error: UNABLE_TO_VERIFY_LEAF_SIGNATURE]
stack: 'Error: UNABLE_TO_VERIFY_LEAF_SIGNATURE\n
at SecurePair.<anonymous> (tls.js:1253:32)\n
at SecurePair.EventEmitter.emit (events.js:91:17)\n
at SecurePair.maybeInitFinished (tls.js:865:10)\n
at CleartextStream.read [as _read] (tls.js:416:15)\n
at CleartextStream.Readable.read (_stream_readable.js:231:10)\n
at EncryptedStream.write [as _write] (tls.js:329:25)\n
at EncryptedStream.Writable.write (_stream_writable.js:176:8)\n
at write (_stream_readable.js:496:24)\n
at flow (_stream_readable.js:506:7)\n
at Socket.pipeOnReadable (_stream_readable.js:538:5)' }
******************************
******************************
{ [Error: read ECONNRESET]
stack: 'Error: read ECONNRESET\n
at errnoException (net.js:846:11)\n
at TCP.onread (net.js:508:19)',
code: 'ECONNRESET',
errno: 'ECONNRESET',
syscall: 'read' }
******************************
When I browse the same endpoint URL in a browser, it throws HTTP 400: Bad Request
I know that it's an SSL type error, and that it's from the server-side. However, I don't know why it's throwing the error and what might be wrong server-side. What do I need to change?
As per the OpenSSL manual here:
21 X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: unable to verify the
first certificate no signatures could be verified because the chain
contains only one certificate and it is not self signed.
With that in mind, it seems that you may need to sign your certificate.