How to check if other users are logged in on Parse via Facebook or some other way? - facebook

I know that if I want to check if PFUser.currentUser is logged with Facebook, I can use:
if FBSDKAccessToken.currentAccessToken() != nil {
print("you logged with FB!!")
//do your stuff.
}
How can I know if in a blogging app, another user is logged on parse via Facebook? (or twitter? or other ways?).
So just to be clear, I don't want to know if CURRENT USER is logged in via FB!, but if ANOTHER user is, still better HOW this user logged in.
For example, in a class named "posts" under the column "author" I have pointer to that user in default "users" class. Is there a way, planned by Parse, in wich I can perform that check? In their docs this case seems to be missing, they only talk about login, linking, referring, but not checking (if not for current user).
should I insert a new column in class User as for example "userLoggedInBy" ??

Related

Parse user not updating for just one specific user

I was wondering if anyone has seen a case where Parse User table doesn't update for a specific user. I have a pretty simple code:
PFUser.current()?["TorF"] = true
PFUser.current()?.saveInBackground(block: { (success, error) in
if error != nil {
print(error)
} else {
}
})
I have checks in other places of the app regarding whether there is a current PFUser, and my database shows that the user is logged in and PFUser.current() is correctly assigned to this user. The simple operation above works for all other users except for one specific user. Has anyone encountered something like this?
I found out that this was happening because the user had changed his password and therefore invalidated his access token. The place to check for whether the user's access token is valid is via Graph request.

Meteor keep track of user sign ins

I would like to keep track of the amount of times that a user has logged into the application to either:
Remind them on their first visit to complete their profile
If profile is not complete, every X amount of visits remind user to complete
I'm not sure if the proper way to do this would be adding a key value to the users collection, or tie login to a new collection which counts up one each time a login occurs.
Is there a built in method to keep track of login successes?
Yup. You can even keep track of login failures.
From http://docs.meteor.com/#/full/accounts_onlogin:
Accounts.onLogin(function() {
// track successful login here. You can just use Meteor.user() to find out which user.
});
Accounts.onLoginFailure(function() {
// track failed login here.
});
There is even a "validate login attempt" method where you could potentially screen your users:
Accounts.validateLoginAttempt(func):
Accounts.validateLoginAttempt(function(loginInfo) {
// loginInfo.user returns a valid user object, if logged in successfully. Maybe tie this one to a collection, and do some checks etc.
// you can even use loginInfo.connection to see where the user has connected from (e.g. IP address.. perhaps)
return true; // return false if you want to 'bounce' this user.
});
Note: These can be done server-side only.

Loose req.session when trying to get more FB privileges via everyauth

I've been doing user authentication with everyauth and Facebook and all works well. Now, I want to integrate an ability to post to Facebook. Since my app asks only for email scope when users first login, I'll need to get a larger FB scope, and am trying to follow the FB guidelines and only ask for this additional scope when I need it.
I added the following code to my everyauth configuration as per the docs:
everyauth
.facebook
.appId(conf.fb.appId)
.appSecret(conf.fb.appSecret)
//TODO add custom redirect for when authentication is not approved
.scope(function (req, res) {
console.log('Setting FB scope');
console.log('Session: ' + util.inspect(req.session));
var session = req.session;
switch (session.userPhase) {
case 'share-media':
return 'email,user_status';
default:
return 'email';
}
})
All is well when an unauthenticated user logs into the application. The problem is that when I want to "up the ante" on FB scope, which I do by setting req.session.userPhase to 'share-media', and then present a link to /auth/facebook to confirm they want to allow posting to FB. When this happens, I get an error that req.session is undefined from the above code (all of req is undefined).
I assume this is since a previously logged-in user is essentially re-authenticating, but isn't that how I would get more scope from Facebook? Am I going about this the wrong way?
Thanks!!!

FB.getLoginStatus with "force"=true only working for some usersadmins when used twice

We have a requirement on our site which forces a user to like a fan page before they can proceed on our site. Since Facebook requires a user to allow access via an app for this type of data, we have an initial call to FB.getLoginStatus which sends the user down three paths, based on the 3 responses (unknown, not connected, connected). Our problem exists in the "unknown" branch. This initial call to FB.getLoginStatus works fine for everyone, if the user is unknown (logged out) we show them the Like Box social widget, then the user clicks on it and logs in (thus liking the page), and then we use the callback of FB.Event.Subscribe('edge.create') to run FB.getLoginStatus again (to check if the user was simply logged out but has previously allowed our app). At that point, if the user previously allowed our app, we allow them to continue, if not we show them an "allow" button and on that user interaction and callback we allow the user to continue. This logic flow works for a hand full of people, including a few of the administrators listed for the app, but not the majority of users. On the second call to FB.getLoginStatus we are using the second parameter "force=true". Can anyone give insight into this behavior and/or point to a thread with a similar glitch? Thanks in advance, this one is a head scratcher!
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
} else if (response.status === 'not_authorized') {
} else {
}
}, {force: 'true'});

Filter Friends that are Online FBML

Ok, I have this array of a users friends, and I'm just wondering how I can filter out the ones that are offline so that I only have the online ones in the array :D
Thanks
You don't need to do that, you just have to account for current logged in user whether it is you or anyone else and behind the scenes it will be however is logged in. You should simply make a check if a user is logged in (any user including friend):
if ($facebook->user > 0 && isset($facebook->user))
{
// your code here....
}
The code in the condition will run only if a user is logged in.