ERROR:the operation couldn't be completed. (com.facebook.sdk error 5.) - facebook

I am getting sdk problem, what I change in the code for removing error?
Please help me, I am new in titanium.
var f = Ti.Filesystem.getFile('pumpkin.jpg');
var blob = f.read();
var data = {
message: 'This is a pumpkin',
picture: blob
};
Titanium.Facebook.requestWithGraphPath('me/photos', data, 'POST', function(e) {
if (e.success) {
alert("Success! From FB: " + e.result);
} else {
if (e.error) {
alert(e.error);
} else {
alert("Unkown result");
}
}
});

you are trying to execute example code from online doc so if you are using traditional structure then put one pic with pumpkin.jpg in resources directory because i think that file should be missing.
and be sure that you are calling after login.

Related

Getting retry limit exceeded error on uploading a few images to Google Storage

I'm not sure what's going on, because I don't get this issue, but a lot of my users report this issue. I have a page that uploads multiple files (the error is happening at 5). Several users report getting the error "storage/retry-limit-exceeded". What's going on? Please help.
In the code below, each error[i][j] gets the same code, which is "storage/retry-limit-exceeded".
My code looks like:
function SubmitFiles(){
pending=true;
let promises = partsofprobs.map((x,i) => {
return x.map((y,j) => FileUpload(i,j));
});
Promise.all(promises.map(x=>Promise.all(x))).then((values)=>{
//DO SOME STUFF WITH THE VALUES -- code removed for brevity, since the error is thrown by the other function.
});
}
function FileUpload(i,j){
return new Promise((resolve, reject) => {
let file=newpicdata[i][j];
if(file){
currentupload[i][j]=true;
let storageRef = storage.ref();
let fileRef = storageRef.child(examid+'/'+i+'/'+j+'/'+$currentUser.uid+'/'+newfiles[i][j][0].name);
let uploadTask = fileRef.putString(file, 'data_url');
uploadTask.on('state_changed',
function(snapshot) {
// Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
let uploadedpercent = (snapshot.bytesTransferred / snapshot.totalBytes)*100;
console.log('Upload is ' + uploadedpercent + '% done');
switch (snapshot.state) {
case 'paused':
console.log('Upload is paused');
break;
case 'running':
console.log('Upload is running');
break;
}
}, function(err) {
console.log("error code: ", err.code);
error[i][j]=err.code;
currentupload[i][j]=false;
reject();
}, function() {
// Upload completed successfully, now we can get the download URL
uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) {
uploadedpicsurls[i][j]=downloadURL;
success[i][j]=true;
currentupload[i][j]=false;
console.log('File available at', downloadURL);
resolve({url:downloadURL,graded:false,score:null,problemindex:i,part:j,grader:null,notes:[],outof:partsofprobs[i][j],beinggradedby:[]});
});
});
}else{
resolve(existingrecord ? existingrecord.solutions[i].parts[j]:{url:null,graded:false,score:0,problemindex:i,part:j,grader:null,notes:[],outof:partsofprobs[i][j],beinggradedby:[]});
}
})
}

Sending a mail with attachment on failed expect

I am trying to attach a .png file to the mail that will be sent via nodemailer on a expect/spec failure run via Protractor.
Worth mentioning is that I am using protractor-jasmine2-screenshot-reporter for screenshot capture.
What I am doing:
browser.driver.wait(function() {
return helper.checkURLAddress(browser.params.Test.URL.mojOLX); //will return false
}, 2000)
.then(function() {
// success code
},
//failure code goes below
function() {
var htmlFilePath = 'D:/Test/target/screenshots/my-report.html';
var htmlFileContent = String(fs.readFileSync(htmlFilePath));
var screenshotDirectory = "D:/Test/target/screenshots/chrome";
helper.sendHTMLMail(htmlFileContent, helper.getMostRecentFileName(screenshotDirectory));
}
The function for getting the most recent file:
function getMostRecentFileName(dir) {
var files = fs.readdirSync(dir);
return _.max(files, function (f) {
var fullpath = path.join(dir, f);
return fs.statSync(fullpath).ctime;
});
}
And the mailOptions with attachments:
var mailOptions = {
//from, to, subject go here
attachments: {
path: htmlFilePath
}
};
The error I am getting is:
Error: ENOENT: no such file or directory, open 'D:/Test/Screenshotname.png'.
The filepath of the screenshot is actually incorrect and is missing 3 directories in the path to get to the PNG(target, screenshots, chrome).
I pressume that it is due to the directories not created, as mentioned in this thread. But the solution here is to wait for the pdf creation, which is done by the user, which is not the case here.
When exactly is the screenshot saved?
Why does the function not use the file it shows in the error?
EDITED Question:
How to call the sendHTMLMail after the screenshots are created?

Read file from GridFS based on _ID using mongoskin & nodejs

I am using mongoskin in my nodejs based application. I have used GridFS to uplaod the file. I am able to upload and read it back using the "filename" however I want to read it back using _id. How can i do? Following are code details.
Working code to read the file based on filename:
exports.previewFile = function (req, res) {
var contentId = req.params.contentid;
var gs = DBModule.db.gridStore('69316_103528209714703_155822_n.jpg', 'r');
gs.read(function (err, data) {
if (!err) {
res.setHeader('Content-Type', gs.contentType);
res.end(data);
} else {
log.error({err: err}, 'Failed to read the content for id '+contentId);
res.status(constants.HTTP_CODE_INTERNAL_SERVER_ERROR);
res.json({error: err});
}
});
};
How this code can be modified to make it work based on id?
After few hit & trial following code works. This is surprise bcz input parameter seems searching on all the fields.
//view file from database
exports.previewContent = function (req, res) {
var contentId = new DBModule.BSON.ObjectID(req.params.contentid);
console.log('Calling previewFile inside FileUploadService for content id ' + contentId);
var gs = DBModule.db.gridStore(contentId, 'r');
gs.read(function (err, data) {
if (!err) {
//res.setHeader('Content-Type', metadata.contentType);
res.end(data);
} else {
log.error({err: err}, 'Failed to read the content for id ' + contentId);
res.status(constants.HTTP_CODE_INTERNAL_SERVER_ERROR);
res.json({error: err});
}
});
};

Baasbox and Javascript

I'm trying BaaSbox, a free Backend as a Service. But it has no out-of-the-box Javascript support I can use right away (yet, only iOS and Android)
I'm having trouble sending the right curl command from javascript, anyone happen to know a good resource or a simple working $.ajax template? I've tried a few examples from stackoverflow, but none of them specifically aimed at BaaSbox.
I've tried following the Java instructions on their site here. Just making a simple login work, but I keep getting the wrong responses from the server.
Or on the other hand, anyone know a good, free alternative to BaaSbox? I just want to be able to install it on my own server, no paid plans or whatever.
in the download page there is a preliminary version of the JS SDK (added few days ago).
The documentation is on the way, however in the zip file you can find a simple example.
For example to perform a signup:
//set the BaasBox parameters: these operations initialize the SDK
BaasBox.setEndPoint("http://localhost:9000"); //this is the address of your BaasBox instance
BaasBox.appcode = "1234567890"; //this is your instance AppCode
//register a new user
BaasBox.createUser("user", "pass", function (res, error) {
if (res) console.log("res is ", res);
else console.log("err is ", error);
});
Now you can login into BaasBox
//perform a login
$("#login").click(function() {
BaasBox.login("user", "pass", function (res, error) {
if (res) {
console.log("res is ", res);
//login ok, do something here.....
} else {
console.log("err is ", error);
//login ko, do something else here....
}
});
Once the user is logged in he can load the Documents belonging to a Collection (the SDK automatically manages the Session Token for you):
BaasBox.loadCollection("catalogue", function (res, error) { //catalogue is the name of the Collection
if (res) {
$.each (res, function (i, item) {
console.log("item " + item.id); //.id is a field of the Document
});
} else {
console.log("error: " + error);
}
});
However under the hood the SDK uses JQuery. So you can inspect it to know how to user $.ajax to call BaasBox.
For example the creatUser() method (signup) is:
createUser: function (user, pass, cb) {
var url = BaasBox.endPoint + '/user'
var req = $.ajax({
url: url,
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({
username: user,
password: pass
}),
success: function (res) {
var roles = [];
$(res.data.user.roles).each(function(idx,r){
roles.push(r.name);
})
setCurrentUser({"username" : res.data.user.name,
"token" : res.data['X-BB-SESSION'],
"roles": roles});
var u = getCurrentUser()
cb(u,null);
},
error: function (e) {
cb(null,JSON.parse(e.responseText))
}
});
}

How to get Meteor.Call to return value for template?

I've tried to understand this post regarding this concept, however, I'm failing to get it. I have the following simple setup:
/server/test.js
Meteor.methods({
abc: function() {
var result = {};
result.foo = "Hello ";
result.bar = "World!";
return result;
}
});
/client/myapp.js
var q = Meteor.call('abc');
console.log(q);
This structure returns to the console undefined.
If I change the myapp.js file to:
Meteor.call('abc', function(err, data) {
!err ? console.log(data) : console.log(err);
}
I receive the Object in my console.
Ideally this is what I'd like to be able to do, but it doesn't work, stating in the console: Cannot read property 'greeting' of undefined
/client/myapp.js
var q = Meteor.call('abc');
Template.hello.greeting = function() {
return q.foo;
}
Any help in passing the data from the server object into the template would be greatly appreciated. I'm still learning JavaScript & Meteor.
Thanks!
From the Meteor.call documentation:
On the client, if you do not pass a callback and you are not inside a stub, call will return undefined, and you will have no way to get the return value of the method. That is because the client doesn't have fibers, so there is not actually any way it can block on the remote execution of a method.
So, you'll want to do it like this:
Meteor.call('abc', function(err, data) {
if (err)
console.log(err);
Session.set('q', data);
});
Template.hello.greeting = function() {
return Session.get('q').foo;
};
This will reactively update the template once the data is available.
This happens because Npm.require has Async behavior. That's the reason that you have to write a callback for Meteor.call.
But there is a solution, just use install(mrt add npm) and you'll get a function named Meteor.sync(//...) with this you can do both games: sync and async in your Meteor.call().
Reference: http://www.sitepoint.com/create-a-meteor-app-using-npm-module/
You can get the return value of a Meteor method for use in a template by using a reactive variable. Check out the working demonstration on Meteorpad
I went for a ghetto solution. But, it works for me, which is what matters, to me. Below is my code, which, in concept, I think, solves OP's problem.
In the client's main.js:
Meteor.setInterval(function() {
confirmLogin();
}, 5000);
This runs the confirmLogin() function every five seconds.
The confirmLogin function (in the client's main.js):
function confirmLogin() {
Meteor.call('loggedIn', function (error, result) {
Session.set("loggedIn", result);
});
}
The loggedIn method (in the server's main.js):
loggedIn: function () {
var toReturn = false;
var userDetails = Meteor.user();
if (typeof userDetails["services"] !== "undefined") {
if (typeof userDetails["services"]["facebook"] != "undefined") {
toReturn = true;
}
}
return toReturn;
},
The relevant helper:
loggedIn: function () {
return Session.get("loggedIn");
}