Meteor: Accounts._storedLoginToken is not a function - javascript

I am using CollectionFS with GridFS to upload images:
Pictures.insert(e.target.files[0], function(err, res) {
if (err) return console.log(err);
this.setState({editing: false});
});
However when uploading I get an error:
Exception in delivering result of invoking '/cfs.pictures.filerecord/insert':
TypeError: Accounts._storedLoginToken is not a function
I've tried calling Accounts._storedLoginToken() in the Meteor shell and it gives the same error.
The error occurs here in the Meteor code:
var authToken = '';
if (typeof Accounts !== "undefined") {
var authObject = {
authToken: Accounts._storedLoginToken() || '',
};
// Set the authToken
var authString = JSON.stringify(authObject);
authToken = FS.Utility.btoa(authString);
}
Any help would be much appreciated.

Did you add accounts-base to your project? Accounts object does not have the _storedLoginToken method until you add a certain pkg such as account-base.

Related

AWS Kendra sdk call will not return results

I have been following the AWS-Kendra react-search app example you can find here:
https://docs.aws.amazon.com/kendra/latest/dg/deploying.html
After importing the Kendra client with:
const kendra = require('aws-sdk/clients/kendra');
const kendraClient = new kendra({apiVersion: '2019-02-03', region: 'us-east-1'});
Any call on kendraClient to any of the kendra services returns null. I have been executing queries with:
const results = kendraClient.query({ IndexId: INDEX_ID, QueryText: queryText});
Which returns a request object with null data and error fields.
I have calls to S3 which execute correctly in the same file so I do not believe it to be an authentication problem. If I had to guess it's some issue with how I created the kendra object and client, the usual
kendra = new AWS.Kendra();
doesn't work because Kendra is not part of the browser version of the SDK.
Are you trying to run js from browser directly? Here is a sample nodejs code
var kendra = require("aws-sdk/clients/kendra");
var kendraClient = new kendra({apiVersion: "2019-02-03", region: "us-west-2"});
exports.handler = function (event) {
try{
console.log("Starting....");
var params = {
IndexId: "<<Enter your indexId here>>",
QueryText: "<<Enter your queryText here>>",
QueryResultTypeFilter: "DOCUMENT",
PageNumber: 1
};
var kendraResponse = kendraClient.query(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log("Kendra result is", data); // successful response
});
const response = {
"dialogAction":
{
"fulfillmentState":"Fulfilled",
"type":"Close","message":
{
"contentType":"PlainText"
}
}
}
return response;
} catch (error) {
console.log(error)
}
};

Creating new users in quickblox not working

I have been trying to create users on quickblox without any success. I have reviewed their documentation and have searched the internet, including SO, to no avail. Below is my code:
var QB = require('quickblox');
//Inizializing quickblox
QB.init(6455, "7j9XXXXXXXX", "DdWCXXXXXXX");
QB.createSession(function(err, result) {
// callback function
console.log('Callback', err, result);//This display 'Callback null undefine'
});
var params = { 'login': 'displayName', 'password': 'userIdert'};
QB.users.create(params, function(err, user) {
if (user)
{
console.log('Sign Up SUCCESS: ', JSON.stringify(user));
} else {
console.log('Sign Up ERROR: ', JSON.stringify(err));
}
});
PS:
I used this to install quickblox in nodejs: npm install quickblox --save
What I've tried
Tried to output the result gotten from createSession() it return null for error and undefine for result
Added QB.users.create() inside the callback function
Use qbuserparam with createSession()

createkeysand certificate aws javascript

I am implementing the following code using javascript in browser to create certificate and key pair:
var iot = new AWS.Iot();
function createCert(){
var params = {
setAsActive:false
};
iot.createKeysAndCertificate(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
};
and I am getting the ERROR as :
UnknownOperationException: null
at Object.s [as extractError] (https://sdk.amazonaws.com/js/aws-sdk-2.106.0.min.js:42:24512)
at constructor.o (https://sdk.amazonaws.com/js/aws-sdk-2.106.0.min.js:42:29401)
Please help me in resolving this error.
Thank You
Seems like I had configured AWS for dynamoDB and the endpoint of AWS.Iot was not updated.
Now, it works!!!

Sending an AlchemyData News query using Node.js (watson-developer-cloud module)

I'm currently working with Node.js using the watson-developer-cloud Node.js SDK and I'm having problems when sending a query that includes an entity.
This is my code:
// require watson's node sdk and fs
var watson = require('watson-developer-cloud');
var fs = require('fs');
// Define output file
var outputJSONFile = '/home/vagrant/Desktop/node/dir/data.json';
// Create alchemy_data_news object using our api_key
var alchemy_data_news = watson.alchemy_data_news({
api_key: ''
});
// Define params for the query and what values to return
// Accepted returne values:
// docs.alchemyapi.com/v1.0/docs/full-list-of-supported-news-api-fields
var params = {
start: 'now-1m',
end: 'now',
count: 2,
qs: ['q.enriched.url.enrichedTitle.entities.entity.text=apple'],
return: ['enriched.url.url,enriched.url.title']
};
// Call getNews method and return json
alchemy_data_news.getNews(params, function (err, news) {
if (err) {
console.log('error:', err);
} else {
fs.writeFile(outputJSONFile, JSON.stringify(news, null, 2), function(err) {
if (err) {
console.log('WriteFile Error:', err);
} else {
console.log("JSON saved to " + outputJSONFile);
}
});
}
});
I'm still trying to figure out how to send the entities parameters using the params object.
While digging up through some code I came across qs so I have been using that to test but I haven't had success at all.
Any suggestions are greatly appreciated.
P.S: I'm trying to pass:
q.enriched.url.enrichedTitle.entities.entity.text=apple
q.enriched.url.enrichedTitle.entities.entity.type=company
If you look at the node-sdk source code for AlchemyDataNews, you will see that the top level parameters are being sent as query strings.
Then params map should be:
var params = {
start: 'now-1m',
end: 'now',
count: 2,
return: ['enriched.url.url,enriched.url.title'],
// fields here
'q.enriched.url.enrichedTitle.entities.entity.text': 'apple',
'q.enriched.url.enrichedTitle.entities.entity.type': 'company'
};

push notifications via quickblox

I am trying to implement push notifications for my app using nodejs for the backend using quickblox. I'm following the steps to do that as mentioned on the quickblox site, i.e create a session user, create a push token, and last subscribe to notification channel. I'm facing a problem with the creation of the push token. My server side code looks like this:
app.post('/test_quickblox', function(req, res) {
var params = {
login: req.user.qb_username,
password: req.user.qb_password,
}
console.log(params);
QB.createSession(params, function(err, result) {
if (err) {
console.log(err);
}
console.log(result);
var options = {};
options.headers = {};
options.headers['QuickBlox-REST-API-Version'] = '0.1.0';
options.headers['QB-Token'] = result.token;
options.body = {};
options.body['push_token'] = {};
options.body['push_token']['environment'] = 'development';
options.body['push_token']['client_identification_sequence'] = '54b1e2b9e9081ed60520824054b1e2b8e9081ed60520823f';
options.body['device'] = {};
options.body['device']['platform'] = 'ios';
options.body['device']['udid'] = 'e0101010d38bde8e6740011221af335301010333';
options.url = 'http://api.quickblox.com/push_tokens.json';
QuickbloxRequest(options, function(err, response) {
if (err) {
console.log(err);
return apiError();
}
console.log(response);
res.apiSuccess();
});
});
});
when logging the response it looks like the following
{ _id: '54b1e3a1535c121c2000be66',
application_id: 18113,
created_at: '2015-01-11T02:44:49Z',
device_id: 0,
nonce: 8394,
token: 'bf61098a35fac9389be236caec44f0a9827630d1',
ts: 1420944288,
updated_at: '2015-01-11T02:44:49Z',
user_id: 2179940,
id: 56046 }
and the error I get is:
{"code":null,"message":"No device registered for current user session. Device is obligatory to be able to execute actions with push token."}
I guess the problem lies in the device_id being 0.
Note that I am creating the users in another controller without supplying any device_id upon creation, so I think that might be my problem but I am new to quickblox and do not understand yet all the semantics so please help me find out what the problem is. Thanks
And here we are 4 years later and I faced the same problem. No answer, no nothing, it makes you wonder how large is the quickblox community :O
Anyway, for anyone coming here with the same problem : It seems the problem is that the Android UUID returned by PhoneGap is too short so quickblox rejects it silently.
Here is what worked for me. Pay attention to the doubling of the uuid :
window.device.uuid + window.device.uuid
JS Code :
//REGISTER AS ANDROID
var message = {
environment: "development",
client_identification_sequence: e.regid,
platform: "android",
udid: window.device.uuid + window.device.uuid,
};
if (BBPushNotification.showLog) console.log(message);
QB.messages.tokens.create(message, function(err, response){
if (err) {
if (BBPushNotification.showLog) console.log("Create token error : ",err);
} else {
if (BBPushNotification.showLog) console.log("Create token success : ",response);
}
});

Categories