I made a unity project and included facebook in it. Everything worked fine until I used OBB spliter.
Actually, I just wanted to share a screenshot of the game so I did this:
private void CallFBLogin()
{
print ("test");
FB.Login("email,publish_actions", LoginCallback);
StartCoroutine (TakeScreenshot ());
print ("test2");
}
When I push a button, this function is called but the problem is that the process finishes before I'm logged with Facebook. When I'm logged in, I'm already out of this function. What's the best way to log, wait to be logged and then launch the coroutine?
I haven't used the Facebook api yet so I can't give you exact code but based on what I see here you need to launch your coroutine from inside the LoginCallback function.
This way it will automatically execute after the user is logged in.
As TheValar stated, you need to do the following..
private void CallFBLogin()
{
print ("test");
FB.Login("email,publish_actions", MyLoginCallback);
print ("test2");
}
void MyLoginCallback(FBResult result)
{
// Do whatever you need, or nothing. You can check if you are logged in correctly
StartCoroutine (TakeScreenshot ());
}
This will guarantee that the take screenshot gets called after you are logged in Facebook
Related
I am stuck with a functionality of the Firebase SDK (Auth package) regarding the Scenes and it's integration. Here's how they work:
1st: Loading Scene
Here, I just added the FirebaseInit code EXACTLY as suggested by Patrick, which it's only function is to call the next scene (Login/Register) once everything loads correctly.
2nd: Login/Register Scene
Here I do all the Login AND ALSO the register logic. I set up a button that alternates between the two (Activating the respective parent gameObject within the Canvas). Once the user log's in, the 3rd scene comes into play.
3rd: App's Main Screen Scene
Main Screen of the app, where the user can LOGOUT and return to the Login Scene.
Problem
I added the 'LoadSceneWhenUserAuthenticated.cs' in the 2nd Scene, and it works (kind of).
It actually does what it is supposed to. If I log in, quit the game without loging out, and open it again, it does come back directly to the 3rd scene. BUT some things are happening and they aren't supposed to.
First
When I Sign Up a user, I call the method 'CreateUserWithEmailAndPasswordAsync()'. Once it completes, it should activate the login screen and stay there, waiting for the user to fill in the password, but the 'FirebaseAuth.DefaultInstance.StateChanged' comes into play and forces the 3rd screen to be loaded, skipping several other steps that should be taken (email registration for example).
Second
As I mentioned in the end of number 1 above, if I try to log in to an account that does not have it's email verified, it works! (due to the 'LoadSceneWhenUserAuthenticated.cs' which is added in the scene). Code:
var LoginTask = auth.SignInWithEmailAndPasswordAsync(_email, _password);
LoginTask.ContinueWithOnMainThread(task =>
{
if (task.IsCanceled || task.IsFaulted)
{
Firebase.FirebaseException e =
task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException;
GetErrorMessage((AuthError)e.ErrorCode, warningLoginText);
return;
}
if (task.IsCompleted)
{
User = LoginTask.Result;
if (User.IsEmailVerified == true)
{
UIControllerLogin.instance.MainScreenScene();
}
else
{
warningLoginText.text = Lean.Localization.LeanLocalization.GetTranslationText($"Login/VerifyEmail");
}
I know that it's possible to fix this issue by adding an extra scene just before the login scene (as Patrick does in the youtube video) but it doesn't make any sense in my app. It would actually only harm the UX of it.
Patrick's Video:
https://www.youtube.com/watch?v=52yUcKLMKX0&t=264s
I'm glad my video helped!
My architecture won't work for every game, and I tried to boil it down to the bare minimum to get folks started. You may be able to get the functionality you want by adding an additional check in HandleAuthStateChanged:
private void HandleAuthStateChanged(object sender, EventArgs e)
{
if (_auth.CurrentUser != null && !_auth.CurrentUser.IsAnonymous && _auth.CurrentUser.IsEmailVerified)
{
SceneManager.LoadScene(_sceneToLoad);
}
}
but it does sound like, at this point, you'll want to build out a more robust registration/sign in flow that fits your use case.
If you need more help, I might suggest re-posting on the community mailing list or the subreddit. Those resources may be more better suited to discussing various pros/cons of different architectures or spitballing ideas (and feel free to link to any new posts in a comment so myself or others interested can follow along).
I'm new with Xamarin form, my question is how can I check user is logged in for entire app, example every time when users go to a new page, it checks for authent. I tried successfully for every page check for auth but is there any another ways to do it? I did some research on internet and some said that i have to auth on the App.cs on OnStart() but the event is not raise when i go to the next page, it starts only when user open the app.
Here is my code, I'm using Google auth.
On the logged in page (HomePage):
public HomePage(NetworkAuthData networkAuthData)
{
if (string.IsNullOrEmpty(networkAuthData.Id))
{
//Always require user authentication
//Application.Current.MainPage.Navigation.PopAsync();
Application.Current.MainPage = new NavigationPage(new SocialLoginPage(oAuth2Service));
}
else
{
BindingContext = networkAuthData;
InitializeComponent();
}
}
It works but when i move these code to app.cs on OnStart() it just run once when opened the app.
I used the following in a straight copy paste from the Parse documentation:
ParseTwitterUtils.logIn(view.getContext(), new LogInCallback() {
#Override
public void done(ParseUser user, ParseException err) {
if (user == null) {
Log.d("MyApp", "Uh oh. The user cancelled the Twitter login.");
} else if (user.isNew()) {
Log.d("MyApp", "User signed up and logged in through Twitter!");
} else {
Log.d("MyApp", "User logged in through Twitter!");
}
}
});
with the exception of the context I'm passing to it. Because I'm inside a button click event which is in a fragment, I pass as context: view.getContext()
I have also called: ParseTwitterUtils.initialize("YOUR CONSUMER KEY", "YOUR CONSUMER SECRET");
before everything with my API Key and API Secret. However, there is no Twitter login dialog appearing. What appears is a small rectangle with text saying: "loading..." and a moving circle, but it closes without opening any authentication dialog. Because of that the done() method part is never being called.
I realize that in order to use the ParseFacebookUtils one needs the Facebook SDK for android and that such SDK is the one that contains the Login Screen. In fact, when I use ParseFacebookUtils, it works perfectly. But there is no SDK with login screen for Twitter in Android. Plus the Parse documentation clearly states that a Twitter Login Dialog is supposed to appear when the code above is executed. No further action needed according to it.
What am I missing here. How do I make the Twitter login dialog appear?
Please make sure you have entered your consumer key, and consumer secret correctly. Next please make sure you follow item 3 in the Parse.Com Android developer guide under setup.
That is,
3. When asked to specify a "Callback URL" for your Twitter app, please insert a valid URL. This value will not be used by your iOS or Android application, but is necessary in order to enable authentication through Twitter.
You must specify a callback URL (a valid URL) although it won't be used. That means, use a made up URL or use something like http://myCompanyWebsite.com/callbackurl. This can be set under the "Settings" tab in your twitter developer console.
I don't use Twitter in my Parse applications, but I was able to duplicate the problem by also missing step 3 and then subsequently fix it.
If you are still having trouble please post your logcat of when you press the click button.
I am trying to use facebook sdk to track total app installs. The unity plugin is working for log in, posting etc. But the FB.PublishInstall method doesn't work. I logged the FBResult object and printed it :
private void CallFBPublishInstall()
{
FB.PublishInstall(PublishComplete);
}
private void PublishComplete(FBResult result)
{
Debug.Log("publish response: " + result.Text.Length);
}
This is printed in logcat:
publish response: 0
I am totally puzzled what is wrong. The installs are not being counted in the app's dashboard in facebook. Anyone knows what I might be doing wrong?
I still don't know why there is no reponse text. But the installs are now appearing in the app's dashboard. I am guessing it takes time for the counter to kick in.
I've been playing around with Parse on Android for a few days, I have a problem with ParseUser.logOut() => it actually doesn't log the current user out.
Here's what I do :
private void onClickOnDisconnect() {
ParseUser.logOut();
currentUser = ParseUser.getCurrentUser(); // should be null but isn't...
invalidateOptionsMenu();
Toast.makeText(getApplicationContext(), "Disconnected...", Toast.LENGTH_LONG).show();
}
After the call to ParseUser.logOut(), ParseUser.getCurrentUser() should return null (says the documentation). Still it returns the previously logged in user.
Even though I restart the app the user is still considered as connected.
I use parse framework v1.3.8 (downloaded a 3 days ago). I don't use Facebook SDK, as I've seen a few questions for that specific case.
Thanks in advance
Somewhere in your app, probably the appDelegate you most likely send this message to the PFUserClass
[PFUser enableAutomaticUser];
in this case the
[PFUser currentUser];
will never return nil;
I had the same issue while incorporating logout functionality with facebook login. The error turned out to quite simple and a basic mistake on my part. I had written the following piece of code in my Application class
ParseUser.enableAutomaticUser();
This creates the user every time you run your application even if you have logged out the last time around. Removing this solved my problem.
As I said in the comments above, I got it to work by :
uninstalling the app
deleting the user on the Parse dashboard
reinstalling the app and signing up again
Then the signout/signin mechanism worked miraculously :|
The only reason I can imagine is that I had previously signed up with this user having Automatic user creation enabled, and it somehow stuck to the user entity in Parse.
Experiencing same bug. Now instead of only checking ParseUser as null, I check username too:
ParseUser currentUser=ParseUser.getCurrentUser()
if(currentUser==null)
{
//user doesn't exist
}
else
{
if(currentUser.getUserName()==null)
{
//user oesn't exist
}
}
Try
ParseUser.getCurrentUser().logOut();
I had the same problem. Actually it was a bug in parse sdk and the problem was solved without changing any of my code, just by installing the latest parse android sdk(1.8.1 at the time of writing).
I had the same issue it was because i has automatic user enabled which causes a new anonymous user to be created, it is also explained here
https://www.parse.com/questions/issues-with-parseuserlogout-on-android
Try to logout the current user object, not the class.
ParseUser.getCurrentUser().logout();
and make sure to delete
ParseUser.enableAutomaticUser();
Edit:
When you logout, the User instance will still available, but with null fields. Parse changes all the user's fields into nulls.
So, if you want to check whether the user is logged in or out, just do the following
if(ParseUser.getCurrentUser().getUsername() == null)
{ // user is out
} else {
// user is in }