Cordova app check if user signed in before closing my app? - facebook

i'am trying to made cordova application that need user login to (google + or Facebook)
so i show button for sign in to (google+ or Facebook)
but after i close the app and open it again i need the sign in button hide depending on last signed in account
i need to know how i can check if user signed after closing my application?
ie check if user subscribe with data login to my app or no?

You can check this when your application gets loaded in
function onDeviceReady() {
// Now safe to use device APIs
//Create small function which check for is access toke valid or not
//which returns Boolean true or false
// Else you can use localStorage.isSignInned and once logged in set it as true.
if(isSignInned)
{
//hide buttons
}
}
You can check facebook javascript api here and google javascript api here
It depends upon how you want your application to work.
I am attaching working sample which i created for Facebook for GooglePlus
hope this helps.!

Related

Unity Facebook SDK: FB.IsLoggedIn / FB.ShareLink issue

I'm trying to create my mobile app user to share my Facebook page and if they do, I give them an in-game item. I'm using the example code provided by Facebook here: https://developers.facebook.com/docs/unity/examples
The first issue is that FB.ShareLink doesn't comeback negative if the user cancels the sharing action. From what I've read, that's on purpose and it only works correctly if the user is logged in and my app is authorized. I tested it and that's true, if I use the login code to first login, it comes back as positive or negative correctly.
The second issue that I'm having though is that FB.IsLoggedIn never comes back negative and I'm not sure how to properly check this because even though it comes back as true, my app is note authorized and FB.ShareLink doesn't return negative when canceled. I start the Login issue and then I press the back arrow to cancel it but FB.IsLoggedIn still comes back as true.
How can I just check if the app is authorized? I'm guessing that's all I need to check before running the FB.ShareLink code.
Any ideas?
Thanks!
First, we try to login asking for the user's e-mail address.
public void LogIntoFacebook() {
List<string> perms = new List<string>() { "email" };
FB.LogInWithReadPermissions(perms, OnLogin);
}
Then you can check to see if you got the e-mail address permission using
AccessToken token = AccessToken.CurrentAccessToken;
if (token.Permissions.Contains("email")) { // do something }
If you do, then you move forward with the Facebook share.

Like option using cordova

I need a web and mobile application which will work on android, iphone and windows as well.
I want to use facebook login for my apps and customer can like my page after login thats why i am using cordova to convert my web app into android app but i need to integrate facebook-like option which i didn't get in plugin.
So i implemented this using oglike
$scope.facebookLike = function() {
if($localStorage.hasOwnProperty("accessToken") === true) {
$http.post("https://graph.facebook.com/me/og.likes?access_token="+$localStorage.accessToken+"&object=https://www.facebook.com/Nxtlife-Technologies-Ltd-UK-180614345644169/?ref=br_rs");
alert("like sucessfully done");
} else {
alert("Not signed in");
$scope.facebookLogin();
}
}
Problem:
The code will not throwing any error but after success message it didin't make any changes to my page. like count is remains same.
og.likes is for Open Graph objects – external URLs, outside of Faceook.
You can not like Facebook pages by any other means than the official Like button.

facebook login give me already authorized this app without automatic returning to the app

My app should implement login with facebook but I have noticed that every time I want to login the facebook tell me you are already authorize this app , the question if I already authorized the app the facebook should return automatically without pressing the okey button as I saw in other applications ?
see the attached image
I fixed my problem by doing the following steps :
1- login to your facebook as admin to your app.
2- go to https://developers.facebook.com/apps/YOUR_FACEBOOK_APP_ID/summary.
3- go to settings > basic > Native IOS app
4- set the Configured for iOS SSO: to enabled
In iOS/Android the FBAccessToken's expiration time is up to 60 days. When you do FBLogin in your app you get the access token. once you get the token you should not do login again(otherwise you will be prompted already authorized this app since your app has already been given an access token earlier which is not expired ). You should reuse the unexpired access token.
Like this :
if FBSDKAccessToken.currentAccessToken() != nil {
print(FBSDKAccessToken.currentAccessToken().userID)
print(currentAccessToken().tokenString)
//OR call the *FBGraphRequest*
}
Note: for in-App browser login (SVC: Safari View Controller)
see more:
https://developers.facebook.com/blog/post/2015/10/29/Facebook-Login-iOS9/
and
https://developers.facebook.com/docs/reference/ios/4.9/class/FBSDKLoginManager/
You need to make sure that your app has the proper URL Prefix in your Build Settings. Also make sure that the URL Prefix matches your Facebook ID/URL Prefix in the Facebook developer app.
Edit: Your issue is probably that the access_token is expiring so it's have to re-ask for permissions.
This will happen if your application did not request offline_access permissions. In the newer SDK offline_access is deprecated and you now have to extend the access_token.
See this link: https://developers.facebook.com/docs/mobile/ios/build/#extend_token
As this Question is already answered , but i would like to add another helpful answer for Swift 3.0 :
While using FB Login in Swift , i having issue and i previously did this way:
let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.loginBehavior = .systemAccount
As this uses , System account to check user is authorized for login or not . Unless you logout and login through different user , application shows same "Already authorized" message in place of Fresh login . So i used this way and this trick does the work :
let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.loginBehavior = .web.
This show Login Screen after logout.
Hope this helps to solve this issue.
Feel free to comment . Thanks.
You should check if there is a current session before logging in with FBSDKLoginManager. Do not use [loginManager logout] before logging in.
if ([FBSDKAccessToken currentAccessToken])
{
NSLog(#"Token is available : %#",[[FBSDKAccessToken currentAccessToken]tokenString]);
// Now get details using graphpath.
} else {
// login with permissions using FBSDKLoginManager and get details using graphpath in completion
}
There is a open bug at facebook.com
https://developers.facebook.com/bugs/190389531089978
But the bug only appears at android, ios works fine.
(btw. same behavior in the foursquare and spotify android app - check it out)
Run your iOS FB application into device not simulator it works fine, and didn't shows the already authorized screen.
Thank you.

iphone how to capture simple login/logout event from web to native

I am developing iPhone application which loads login page of my website. I am able to load my login page using phonegap/childbrowser. I am newbie to JS, Phonegap.
How do my native/phonegap application should handle logout and login event has performed on the webpage? Please guide me how to know user has logged out.
Also is it possible to add support for Push Notification in phonegap/childbrowser application ? How?
So far have seen facebook login-logout questions around but hard to understand and couldnt simulate similar approach.
does your whole app run using the childbrowser? If so why not just have the login log out as piece of your app?
Also if you have to use the childbrowser best bet is to set up a locationchange event and if the location equals a login success page then append some arguments and store those using localstorage.
example -
client_browser.onLocationChange = function(loc){
locationchange(loc);
};
function locationchange(loc){
if(loc.indexOf("http://www.example.com/success?login=true&user=foo") > -1){
var user = loc.match(/user=(.*)$/)[1]; // grab user info
localStorage.setItem('login','true'); // set login as true
localStorage.setItem('user',user); // set username
}
}
that will save to your app locally that the user is logged in and their username, which you can use later if you need to use the childbrowser by passing that in the url you open and on the server side you'll have to look for those arguments.
to log out just open the childbrowser and send a logout argument
www.example.com/logout?user=foo
and in your localStorage
localStorage.setItem('login','false');
Honestly this is kind of a vague question, it would really help to understand why you're wanting to do this in the childBrowser vs your app...

How to logout from facebook from the application in iphone?

Please help me with a solution!.I have a iPhone app which uses the new facebook sdk(FBConnect).The app is related to video sharing.I should embed a logout button to sign out the current user from my app.I implemented it by calling fn{currentAPICall = kAPILogout;[[facebookObject]logout:self]} from my wrapper class.....tis logout shd call the logout method in facebook.m.The code is executed as expected but it does not logout from my app,again on relaunching my app it is redirected to the previous account.
Any solutions!
In the DidLogout code, remove the NSDefaults that you stored for the session. Just set them to ""