Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

ACAccountStore always returns 0 Facebook accounts...?

$
0
0

Hi all,

I'm trying to get my app to recognise a Facebook account which is already verified on the phone, yet it always returns no accounts. I have tested in the simulator and on 5c and 5s devices, all using iOS7, and all with the same result.

I am using code as below, modified from this question: http://forums.xamarin.com/discussion/247/using-monotouch-social-and-facebook-authentication

// retrieve facebook login
if (_accountStore == null) {
    _accountStore = new ACAccountStore();
}

var accountType = _accountStore.FindAccountType(ACAccountType.Facebook);
var facebookAccounts = _accountStore.FindAccounts(accountType);
if (facebookAccounts == null || !facebookAccounts.Any()) {
    // THIS CODE IS _ALWAYS_ EXECUTED AS facebookAccounts.Length == 0
    // I HAVE ADDED A FACEBOOK ACCOUNT TO EACH DEVICE, YET NONE OF THEM ARE RECOGNISED

    // show facebook login
    var facebookConnector = new FacebookConnector(this, _services, ConnectFacebook_Success, ConnectFacebook_Error);
    _loadingOverlay = new LoadingOverlay(UIScreen.MainScreen.Bounds, "Connecting to Facebook...");
    View.Add(_loadingOverlay);
    facebookConnector.RequestAuthorisation();
    return;
}

var facebookAccount = facebookAccounts.First();
try 
{
    _accountStore.RenewCredentials(facebookAccount, (renewalResult, renewalError) => {
        if (renewalResult == ACAccountCredentialRenewResult.Renewed)
        {
            ConnectFacebook_Success(facebookAccount.Credential.OAuthToken);
        }
        else if (renewalResult == ACAccountCredentialRenewResult.Rejected || renewalResult == ACAccountCredentialRenewResult.Failed)
        {
            var options = new AccountStoreOptions() {
                FacebookAppId = Constants.FacebookAppId
            };
//          options.SetPermissions(ACFacebookAudience.Friends, new[] {
//              "email", "user_birthday"
//          });
            _accountStore.RequestAccess(accountType, options, (authorised, accessError) => {
                if (authorised) {
                    ConnectFacebook_Success(facebookAccount.Credential.OAuthToken);
                }
                else {
                    ConnectFacebook_Error(accessError.Code == 7 ? OAuthConnectorResult.Cancelled : OAuthConnectorResult.Error);
                }

            });
        }
        else {
            ConnectFacebook_Error(OAuthConnectorResult.Error);
        }
    });
}
catch (Exception) 
{
    ConnectFacebook_Error(OAuthConnectorResult.Error);
}

Am I missing something obvious here?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>