Fetch node issue - javascript

This code is using to bring BNB price, I want to push the price into an array. I tried Fetch in HTML page, and it worked perfect.

Node doesn't have fetch as the browser's JavaScript does.
You can try to use the Node's http module directly or use some package like axios.
UPDATE:
However, regarding your particular case - it seems you don't have do make requests manually. You're using node-binance-api package that does requests under the hood. So just remove the code that invokes fetch at all.
ANOTHER UPDATE:
So finally to add a price to the array you can rewrite your function fetchCoinPrice like this:
function fetchCoinPrice() {
binance.prices(function(error, ticker) {
console.log("Price of BNB: ", ticker.BNBBTC);
array.push(ticker.BNBBTC);
});
}

Related

matrix-js-sdk setup and configuration

I am having some issues trying to connect to a matrix server using the matrix-js-sdk in a react app.
I have provided a simple code example below, and made sure that credentials are valid (login works) and that the environment variable containing the URL for the matrix client is set. I have signed into element in a browser and created two rooms for testing purposes, and was expecting these two rooms would be returned from matrixClient.getRooms(). However, this simply returns an empty array. With some further testing it seems like the asynchronous functions provided for fetching room, member and group ID's only, works as expected.
According to https://matrix.org/docs/guides/usage-of-the-matrix-js-sd these should be valid steps for setting up the matrix-js-sdk, however the sync is never executed either.
const matrixClient = sdk.createClient(
process.env.REACT_APP_MATRIX_CLIENT_URL!
);
await matrixClient.long("m.login.password", credentials);
matrixClient.once('sync', () => {
debugger; // Never hit
}
for (const room of matrixClient.getRooms()) {
debugger; // Never hit
}
I did manage to use the roomId's returned from await matrixClient.roomInitialSync(roomId, limit, callback), however this lead me to another issue where I can't figure out how to decrypt messages, as the events containing the messages sent in the room seems to be of type 'm.room.encrypted' instead of 'm.room.message'.
Does anyone have any good examples of working implementations for the matrix-js-sdk, or any other good resources for properly understanding how to put this all together? I need to be able to load rooms, persons, messages etc. and display these respectively in a ReactJS application.
It turns out I simply forgot to run startClient on the matrix client, resulting in it not fetching any data.

Using meteor's simple:rest package in publications with arguments

I a meteor app, using the simple:rest package to access publications works very nicely!
However, I didn't manage yet to GET a publication that requires an argument.
The docs say nothing about publications with arguments.
When I call the GET URL without argument http://localhost:3000/publications/export/, I get an error message (as I check for the argument in my publication)
When I call get URL with attached argument: http://localhost:3000/publications/export/12345/ the main app gets loaded instead (well, with some broken links to images)
When I add an url option to the publication
Meteor.publish("export", function exportPublication(id) {...}, {
url: "export/:0",
})
it doesn't help, I still get the main app.
The example at https://github.com/stubailo/meteor-rest/blob/master/packages/rest/rest-tests.js suggests that using the URL option seems to be the correct way to define a route for a publication with arguments.
What am I missing?
I haven't used this package myself, but I think you need to add the parameter to the publish function, like this:
Meteor.publish("export", function exportPublication(id) {...}, {
url: "export/:0",
})
and you can access id in the code that retrieves the data. If you are treating it as a number, you may need to parse it: parseInt(id, 10)
Also I would use postman or curl to access the URL (it sounds like you are using the browser)
Oh, when I publish the url as export/:0, then it is mapped to http://localhost:3000/export/123 - but not to http://localhost:3000/publications/export/123. I thought the "publications" would be added automatically.

Node Telegraf callback button

For what we need to pass data to callback button in in simple keyboard (not inline), if thats doesn’t matter?
Example:
const mainMenuKeyboard = Markup.InlineKeyboard([
Markup.callbackButton('Add', 'addAction),
]).resize().extra();
Now, If I want to catch "addAddress" action, I can just do this:
bot.action('addAction',(ctx) => <WHATEVER>);
Everything works just fine&
But, when I want to use simple keyboard (not inline) in my project I cant catch this action using "bot.action("addAction")" I have to use "bot.hears("Add")" :
const mainMenuKeyboard = Markup.keyboard([
Markup.callbackButton('Add', 'addAction),
]).resize().extra();
Don’t work
bot.action('addAction',(ctx) => <WHATEVER>);
Work
bot.hears('Add',(ctx) => <WHATEVER>);
You shouldn't be using Markup.callbackButton (which is InlineKeyboardButton on the Bot API) inside Markup.keyboard(ReplyKeyboardMarkup).
According to Telegram Bot API docs, Markup.keyboard(ReplyKeyboardMarkup) should contain Array of Arrays (not just an array BTW, fix that as well) of KeyboardButton. And Markup.callbackButton(which is Inlinekeyboardbutton on the API) should be used for InlineKeyboard (not reply keyboard).
For more examples on how to use these on telegraf, check this example out

How can I delete all data from multiple Baqend tables?

I need to delete all rows from multiple tables, programmatically (not in the dashboard). Is there an API for that? I couldn't find it in the documentation.
You are right, this is currently not documented. You can however find the REST call in our API Explorer although you don't get the syntactic sugar from the JS SDK. The REST call is a DELETE to /db/{bucket} where bucket is the name of the Table to delete. With the JS SDK this request is wrapped into a message object TruncateBucket, you can use it like this:
DB.login("userWithAdminRole", "<password>").then(function() {
return DB.send(new DB.message.TruncateBucket('<table>'));
}).then(function () {
console.log('truncated!');
}).catch(function() {
console.log('catch truncated!');
});
Note: If you are calling this code from your frontend you need the
admin role (hence the DB.login). If you are calling the code from a
backend module (where you always have the node role) you can skip
the login.
You can also try out all REST request in the API Explorer. It looks like this:

Facebook Graph API - Tagged Places in version 2.0

I used the Graph API with javascript to fetch all of my data contained locations in v1.0.
( I used FB.api("/v1.0/me/locations", function (response) { ... }); )
I know that the updated version is 2.2 and the "locations" node is replaced by "tagged_places" node in v2.0 and above.
I also use the Graph API Explorer to test my results.
I try this, GET: /v2.2/me?fields=tagged_places
and the results are exactly what I want.
However, in my js code, I try: FB.api("/v2.2/me?fields=tagged_places", function (response) { ... });
and there is NO any results!
Besides,
I set version: 'v2.2' in Parse.FacebookUtils.init();
I also ask the permissions :user_tagged_places,user_photos,user_status,user_friends,user_about_me,user_birthday,read_stream in Parse.FacebookUtils.logIn();
I need almost all of the data of my checkins(a.k.a locations in v1.0/tagged_places in v2.0) to add into my database.
I try to fetch /me/photos, but the results are not satisfied. So I still need to use maybe this: FB.api("/v2.2/me?fields=tagged_places", function (response) { ... });
So... can anyone help me? please....
I went through permissions in groups testing them out and I figured out what the problem was.
You need to have the permission of the item you were tagged in.
So in my case I was tagged in photos, so I needed user_photos permission to gain access to user_tagged_places. It actually creates quite an issue because you need to know how a user was tagged to retrieve their tagged_places.
If a user was tagged at a place in a post you need a different permission than if they were tagged in a photo.

Categories

Resources