I tried the old Facebook API method, it deprecated and won't work anymore. Right now I'm used /me/likes/{page-id} to retrieve whether my facebook account likes this page or not. I need to detect users are liking all the fan pages before specific action is taken.
FB.api("me/likes/184522495376661", function(response) {
if ( response.data.length === 1 ) {
FB.api("me/likes/1125511580839629", function(response) {
if ( response.data.length === 1 ) {
FB.api("me/likes/1603408753260758", function(response) {
if ( response.data.length === 1 ) {
// Specific action takes place here
} else {
alert("You haven't like third page!");
console.log(JSON.stringify(response));
}
});
} else {
alert("You haven't like second page!");
console.log(JSON.stringify(response));
}
});
} else {
alert("You haven't like our first page!");
console.log(JSON.stringify(response));
}
});
Each user required Facebook Login before detect the page likes.
FB.login(function (response) {
if (response.status === "connected") {
var uID = response.authResponse.userID;
fb_id = uID;
}else if (response.status === "not_authorized") {
}
},{ scope: 'email,user_likes,public_profile' });
The above codes work for my personal facebook account. But when it comes to other facebook id, the me/likes/{page-id} returns null, but that particular Facebook account already like the page, the API doesn't detect.
Related
My application is powered by jQuery mobile and uses geolocation.
After my application attempts to get the user's location, the (Chrome) browser prompts the user:
Example.com wants to track your physical location [allow] [deny]
My goal is:
If the user clicks "Allow", function 1 is called (location is used
by app).
If the user clicks "Deny", function 2 is called (address form
appears).
How can I bind a function to the event that occurs (if any) when the user clicks the "Allow" or "Deny" button?
The getCurrentPosition function accepts two function arguments. Heck, the first is executed when you allow and the other when you deny!
Documentation
http://jsfiddle.net/pimvdb/QbRHg/
navigator.geolocation.getCurrentPosition(function(position) {
alert('allow');
}, function() {
alert('deny');
});
Link to Docs
function handlePermission() { navigator.permissions.query({name:'geolocation'}).then(function(result) {
if (result.state == 'granted') {
report(result.state);
geoBtn.style.display = 'none';
} else if (result.state == 'prompt') {
report(result.state);
geoBtn.style.display = 'none';
navigator.geolocation.getCurrentPosition(revealPosition,positionDenied,geoSettings);
} else if (result.state == 'denied') {
report(result.state);
geoBtn.style.display = 'inline';
}
result.onchange = function() {
report(result.state);}});}function report(state) {
console.log('Permission ' + state);}
I hope this works.
My current code checks the country code and then changes the drop down value before submitting it for the things to refresh in right currency pricing, but I've tried things like, putting return; to stop it after running it once and moving return; on different line with no luck. I even combined the .val line with .change() thinking maybe having it on separate lines was running it multiple times and refreshing it multiple times.
Here is my code;
$.ajax({
url: "https://ipinfo.io/json",
type: "GET",
success: function(location) {
if (location.country === 'AU') {
$(".shopify-currency-form select").val("AUD").change();
} else if (location.country === 'AR') {
$(".shopify-currency-form select").val("ARS");
} else if (location.country === 'CA') {
$(".shopify-currency-form select").val("CAD");
} else if (location.country === 'US') {
$(".shopify-currency-form select").val("USD").change();
}
return;
}
} );
$('.shopify-currency-form select').on('change', function() {
$(this)
.parents('form')
.submit();
return;
});
When I click the follow button, socket.io sends some data to the server, and then the server sends back a response number. According to what the number is, js alerts a message. But if I click the button a second time, js will alert the same message twice, and if I click it again, three times and so on. If I refresh the page, it starts all over again (click it once, alert shows up once, click it twice, alert shows up twice...)
Here's the code:
$('.followUser').click(function(e){
e.stopImmediatePropagation();
e.preventDefault();
var user= $(this).parent().parent().parent().parent().next().children().children('.userName').children().first().children().attr('id');
var thisUserId = $.cookie('thisUserID');
if(user != thisUserId){ //if he tries to follow himself
var object = {
user: user,
userId: thisUserId
}
socket.emit('followUser', object); //server just adds that user to the following list of the first user
socket.on('followUserResults', function(data){
if(data == 1){
alert('Something went wrong! Please refresh this page and try again'); // if they changed the id on html
} else if(data == 0){
alert('User was added to your following list!');
} else if(data == 2){
alert('This user is already on your following list!');
}
});
} else {
return false;
}
Can you please help me with that? Thank you!
I am slightly unclear as to what is trying to be achieved but I've noticed an error in your code straight away.
This code should be outside of the $('.followuser').click function:
socket.on('followUserResults', function(data){
if(data == 1){
alert('Something went wrong! Please refresh this page and try again'); // if they changed the id on html
} else if(data == 0){
alert('User was added to your following list!');
} else if(data == 2){
alert('This user is already on your following list!');
}
});
So your code should read like:
$('.followUser').click(function(e){
e.stopImmediatePropagation();
e.preventDefault();
var user= $(this).parent().parent().parent().parent().next().children().children('.userName').children().first().children().attr('id');
var thisUserId = $.cookie('thisUserID');
if(user != thisUserId){ //if he tries to follow himself
var object = {
user: user,
userId: thisUserId
}
socket.emit('followUser', object); //server just adds that user to the following list of the first user
} else {
return false;
}
socket.on('followUserResults', function(data){
if(data == 1){
alert('Something went wrong! Please refresh this page and try again'); // if they changed the id on html
} else if(data == 0){
alert('User was added to your following list!');
} else if(data == 2){
alert('This user is already on your following list!');
}
});
Try put the socket.on(...) outside the click callback function, if still not working properly, I would need watch the server code.
I'm working on a chat app with Meteor and I don't want users to be able to copy/paste things into the form for obvious spam reasons. Is this possible? Here is the code I use to run the chat app:
Javascript:
// render all of our messages in the ui
Template.chatBox.helpers({
"messages": function() {
return chatCollection.find();
}
});
// get the value for handlerbar helper user
Template.chatMessage.helpers({
"user": function() {
if(this.userId == 'me') {
return this.userId;
} else if(this.userId) {
getUsername(this.userId);
return Session.get('user-' + this.userId);
} else {
return 'anonymous-' + this.subscriptionId;
}
}
});
// when Send Chat clicked at the message to the collection
Template.chatBox.events({
"click #send": function() {
if (Meteor.user() == null) {
alert("You must login to post");
return;
}
$('#messages').animate({"scrollTop": $('#messages')[0].scrollHeight}, "fast");
var message = $('#chat-message').val();
// check to see if the message has any characters in it
if (message.length < 1) {
alert("You must enter a message to post.");
return;
}
chatCollection.insert({
userId: 'me',
message: message
});
$('#chat-message').val('');
//Validation
var bot =Check_bots();
if(bot==false)
{
//add the message to the stream
chatStream.emit('chat', message);
}
else
{
alert("Slow down! No need to post that fast.");
return false;
}
},
"keypress #chat-message": function(e) {
if (Meteor.user() == null) {
alert("You must login to post");
return;
}
if (e.which == 13) {
//Validation
var bot =Check_bots();
if(bot==false)
{
$('#messages').animate({"scrollTop": $('#messages')[0].scrollHeight}, "fast");
console.log("you pressed enter");
e.preventDefault();
//repeat function from #send click event here
var message = $('#chat-message').val();
// check to see if the message has any characters in it
if (message.length < 1) {
alert("You must enter a message to post.");
return;
}
chatCollection.insert({
userId: 'me',
message: message
});
$('#chat-message').val('');
//add the message to the stream
chatStream.emit('chat', message);
}
else
{
alert("Slow down! No need to post that fast.");
return false;
}
}
}
});
chatStream.on('chat', function(message) {
chatCollection.insert({
userId: this.userId,
subscriptionId: this.subscriptionId,
message: message
});
});
var lastintime=0;
var defference=0;
var msg_count=0;
function Check_bots()
{
var seconds = new Date().getTime() / 1000;
seconds=parseInt(seconds);
if(lastintime < seconds)
{
defference = seconds -lastintime;
lastintime=seconds;
if(defference<=5 && msg_count>=3)
{
return true;
}
else
{
return false;
}
}
}
I have no idea where to even start with this. How do you prevent copy/pasting?
It's not a good idea. Internet Explorer has a onpaste event, and there's been a convoluted implementation on Stack Overflow, but in general it's messy, crosses lines that generally shouldn't be crossed in web design, impossible to pull off completely across all browsers, and can be circumvented without too much trouble.
It's a far better idea to put character-rate limits and detect red flags for spam, like high link density and repetition.
I have a simple facebook validation i would like to implement to my jQuery button.
When the user clicks the button it should check if logged in, if TRUE then change the text.
I found this article which talks about returning a true/false state but when i tried to implement it in my code it didnt work.
Any suggestion where im going wrong please, thank you.
function fb_loginCheck(){
FB.getLoginStatus(function(response, e) {
if (response.status === 'connected') {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
e.returnValue = true;
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook, but has not authenticated your app
fb_oAuth();
e.returnValue = false;
} else {
// the user isn't logged in to Facebook.
fb_oAuth();
e.returnValue = false;
}
}, true);
}
$('.myBttn').click(function(){
var io = return fb_loginCheck();
if (io){
$this = $(this).text();
if($this == 'yes')
$(this).text('no');
else
$(this).text('yes');
}
return false;
});
got it to work:
similar to potench answer but removing the e.returnValue did it
function fb_loginCheck(callBack){
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
callBack(true);
} else if (response.status === 'not_authorized') {
fb_oAuth();
callBack(false);
} else {
fb_oAuth();
callBack(false);
}
}, true);
}
Something like this might work. I've moved the methods around so they get fired when a response is returned from the FB.getLoginStatus method.
I'm passing in a callBack method which fires when the response from FB.getLoginStatus returns a result. Also note that I've had to re-scope the $(this) variable.
function fb_loginCheck(callBack){
FB.getLoginStatus(function(response, e) {
if (response.status === 'connected') {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
e.returnValue = true;
callBack(true);
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook, but has not authenticated your app
fb_oAuth();
e.returnValue = false;
callBack(false);
} else {
// the user isn't logged in to Facebook.
fb_oAuth();
e.returnValue = false;
callBack(false);
}
}, true);
}
$('.myBttn').click(function(){
var targ = $(this);
fb_loginCheck(function (io) {
targ.text( (io) ? "yes" : "no" );
});
return false;
});