Why does Facebook stream.share return undefined when a user publish a status or click "Skip"?
I'm currently trying to use this, so if the user doesn't publish the content, no action should happen, but if the user publish the content an action should happen.
How do I do this?
You can use the graph API feed dialog to publish a post and know if it was published or not by the user:
FB.ui(
{
method: 'feed',
message: '',
name: 'name here',
caption: 'caption here',
description: 'description here',
picture: 'picture url here',
link: 'http://yourlinkurlhere.com',
actions : [{name : 'action name', link : 'action link'}]
},
function(response) {
if (response && response.post_id) {
// Post was published
} else {
// Post did get published
}
});
Related
I am sending chat message with custom parameters to Quickblox api.
message: {
body: 'something',
date_sent: 'some date',
dialog_id: 'dialog id',
extension: {
save_to_history: 1,
},
markable: 1,
type: dialog.type === 3 ? 'chat' : 'groupchat',
customParameter: 'this is custom param',
},
I am sending this to quickblox like this
QB.chat.send(jidOrOpponentId, message);
When I receive that message on other browser, it comes without my custom parameter.
Does anybody know should this custom parameter be returned to me or not? If not, what is it for, anyway?
I read the docs and there is a section on custom params,but there is no explanation on what are they for and should quickblox return them in response.
Try to put the customParameter into the extension object:
var msg = {
type: 'chat',
body: 'How are you today?',
extension: {
save_to_history: 1,
customParameter: 'Custom parameter'
}
};
var opponentId = 78;
QB.chat.send(opponentId, msg);
I am building a command line interface in node.js using library: inquirer.
based on my need I want to render prompt, confirmation text etc when user input's. example.
inquirer usage
var _questions = [{
'type': 'list',
'name': 'databasetype',
'message': 'Choose database :',
'choices': ['mongoDB', 'mysql [alpha]', 'firebase [alpha]', 'url [alpha]'],
'default': 'mongoDB'
}, {
'type': 'input',
'name': 'xfactor',
'message': 'X Factor [email, username etc..] :'
}]
// show question's.
Inquirer.prompt(_questions).then(async (__answers) => {
console.log(__answers)
})
what i want
if user chooses mongoDB than it should render another prompt asking
mongodb url
You can use the when question property, its value should be a function that returns a boolean; true for show question, false for don't show question
so using your example:
_questions = [{
type: 'list',
name: 'databasetype',
message: 'Choose database :',
choices: ['mongoDB', 'mysql [alpha]', 'firebase [alpha]', 'url [alpha]'],
default: 'mongoDB'
}, {
type: 'input',
name: 'url',
message: 'Enter the URL',
when: (answers) => answers.databasetype === 'mongoDB'
}]
see more examples here when usage examples
Iam trying to share a page of my website in facebook , for that iam using this function share:
var publish = {
method: 'feed',
message: 'getting educated about Facebook Connect',
name: 'Connect',
caption: 'The Facebook Connect JavaScript SDK',
description: (
'A small JavaScript library that allows you to harness ' +
'the power of Facebook, bringing the user\'s identity, ' +
'social graph and distribution power to your site.'
),
link: 'http://fbrell.com/',
picture: 'http://fbrell.com/f8.jpg',
actions: [
{ name: 'fbrell', link: 'http://fbrell.com/' }
],
user_message_prompt: 'Share your thoughts about RELL'
};
FB.ui(publish, Log.info.bind('feed callback'));//This line shows the error
But while running the code i get the error as Log is not defined. What is wrong with this code????
I am building an application where users can create event and other users can "join" and add comments to events, also they can open a chat between them, I have a model named "Notification" where I want to store all the notifications in the system and I want to warn to the owner of the event whenever a user comment on his events, write a new message to him, etc.
This is the part of code for comments that I have wrote:
Notification Model:
/* Notification.js */
module.exports = {
attributes: {
title: {
type: 'string',
required: true
},
text: {
type: 'string'
},
type:{
type: 'string',
enum: ['new_assistant', 'cancel_assistant', 'new_message', 'new_comment'],
required: 'true'
},
read: {
type: 'boolean',
defaultsTo: false
},
user: {
model: 'user'
}
}
};
This is where I subscribe the socket to his notification model:
Notification.find({
user: owner_id
}).then(function(notifications) {
return Notification.watch(req.socket);
});
And whenever a user comment in an event I create a new Notification record:
Notification.create({
title: 'A new user has comment',
text: "Hola",
type: 'new_comment',
read: false,
user: event.owner
}).then(function(comment) {
return Notification.publishCreate({
id: notification.id,
title: 'A new user has comment'
});
});
That code run but this sent a socket message to all users and I just want to warn to the owner of the event (And in the future to the users who going to this event).
Thank you so much.
watch sends the model instance creation message to all of the sockets that are watching the model, the same registration could have been performed without finding the notification as it's not instance dependent, i.e. just call: Notification.watch(req.socket);
To send the notification to a single subscriber use sails.sockets
Create a room for the owner when you want to subscribe:
sails.sockets.join(req.socket, owner_id);
And when you want to publish broadcast to this room:
Notification.create({
title: 'A new user has comment',
text: "Hola",
type: 'new_comment',
read: false,
user: event.owner
}).then(function(comment) {
sails.sockets.broadcast(event.owner, {
id: notification.id,
title: 'A new user has comment'
});
});
I've built a web app utilizing the Instagram API. I have the below code in my 'server.js' file, the main file on my node server. The problem is, the 'text' value is often 'null' (whenever an Instagram user does not caption their image). This null value crashes my app. How would I improve this code to account for this situation?
My idea is to provide a default value for 'text' that is inserted whenever 'text' is null.
//Save the new object to DB
Stadium.findOneAndUpdate( {object_id: data.object_id}, { $push: {'photos':
{ img: image.data[0].images.standard_resolution.url,
link: image.data[0].link,
username: image.data[0].user.username,
profile: image.data[0].user.profile_picture,
text: image.data[0].caption.text
}}},
{ safe: true, upsert: false },
function(err, model) {
console.log(err);
}
);
//Send a socket to client with the new image
newImage({
img: image.data[0].images.standard_resolution.url,
link: image.data[0].link,
username: image.data[0].user.username,
profile: image.data[0].user.profile_picture,
text: image.data[0].caption.text
});
Use an unary conditional to check first if the caption even exists
text: image.data[0].caption ? image.data[0].caption.text : 'No caption'