简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM