Switching between two accounts using IOS6 settings - facebook

I've been trying for the past two days to connect to multiple accounts for my app, without success.
I've read that there was potentially a problem with Facebook SDK not clearing the cached token correctly. I am using version 3.1.1.
Here is how it goes.
From fresh install:
Connect to account 1.
Launch game and login successfully. Everything is fine.
Close the game
Goto settings and change to account 2.
Launch game, login failed.
I Am receiving that error code from openActiveSessionWithReadPermissions : FBSessionStateClosedLoginFailed
And even if I press the OK button when Facebook is asking for my permission to access my info, the granted variable that comes back says NO.
The research I did brought me multiple solutions that failed, unfortunately.
I tried resynchronizing with this function:
- (void)fbResync
{
ACAccountStore *accountStore;
ACAccountType *accountTypeFB;
if ((accountStore = [[ACAccountStore alloc] init]) && (accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook] ) )
{
NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB];
id account;
if (fbAccounts && [fbAccounts count] > 0 && (account = [fbAccounts objectAtIndex:0]))
{
[accountStore renewCredentialsForAccount:account completion:^(ACAccountCredentialRenewResult renewResult, NSError *error)
{
//we don't actually need to inspect renewResult or error.
if (error){
}
}];
}
}
fbAccounts always return me an empty array. So I cannot really resynchronize.
I also tried to clear facebook token in my status switch
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
{
[FBSession.activeSession close];
[FBSession.activeSession closeAndClearTokenInformation];
// Clear out the Facebook instance
[self.facebook logout];
self.facebook.accessToken = nil;
self.facebook.expirationDate = nil
}break;
No matter what I do, It seems that I cannot completely get rid of my facebook token.
The only way I found was to reset the settings of the IPAD which is not a solution.
Does anybody have more options I could try?
Thanks!
Tickets I'm aware of :
Facebook authorization fails on iOS6 when switching FB account on device
Facebook SDK 3.1 - Error validating access token

Related

Unable to implement a custom Facebook login button for IOS

I am trying to create a custom login button for IOS 9,i have been following the Facebook's tutorial for doing so but when i button is clicked,i end up getting this error
libc++abi.dylib: terminate_handler unexpectedly threw an exception
I have been following this Facebook tutorial,only difference is i am using dispatch_async due to some reasons.
https://developers.facebook.com/docs/facebook-login/ios#loginkit
dispatch_async(dispatch_get_main_queue(), ^{
NSMutableArray* Permissions = [[NSMutableArray alloc] init];
[Permissions addObject:#"email"];
[Permissions addObject:#"public_profile"];
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithReadPermissions:Permissions
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error)
{
NSLog(#"Process error");
}
else if (result.isCancelled)
{
NSLog(#"Cancelled");
}
else
{
NSLog(#"Logged in");
}
];
});
I have tried using Parse SDK's code too like so...
NSArray *permissionsArray = #[ #"user_about_me", #"user_relationships", #"user_birthday", #"user_location"];
[PFFacebookUtils logInInBackgroundWithReadPermissions:permissionsArray block:^(PFUser *user, NSError *error)
{
if (!user)
{
NSLog(#"Uh oh. The user cancelled the Facebook login.");
}
else if (user.isNew)
{
NSLog(#"User signed up and logged in through Facebook!");
}
else
{
NSLog(#"User logged in through Facebook!");
}
}];
But both the time,i end up getting the same error like as shown in the image below..
Error message image
Am i doing something wrong in app validation process?
Please help!
Thank you!
This is weird,after playing around in Xcode,i found that it is not able to get my appID and other settings from my plist even though it's there.After i programmatically set my app id using
[FBSDKSettings setAppID:#"appid"];
[FBSDKSettings setDisplayName:#"displayname"];
I was to able get rid of that error,but i am stuck at URLSchemes...i will recreate the project and try again!
Thank you!
It's working now and,i am able to get a login page,but after i get past the app login screen,i am getting a blank white screen with only a done button at th top right corner,when i click it,i get the log message that the user cancelled login.

Facebook Login ask to install (iPhone)

I need help in the facebook login from Facebook-SDK-3.1 for iOS 6.I have used all the code of the Facebook sdksample code sessionLoginSample,I have used the WebView opening code in this and whenever i login from the new id ...it takes me to the below image link to install in my project .dont know what exactly it is...and if i do so and after that logout from the code ..and when I again press button to login , it automatically log-in without asking for the id and pssword``login page. and again again it automatically logs-in , even after logout./.can anyone help me why after being logout it ask stores the previous access token and password.
and code is
- (IBAction)buttonClickHandler:(id)sender {
AppDelegate* appDelegate = [[UIApplication sharedApplication]delegate];
if (appDelegate.session.isOpen) {
[appDelegate.session closeAndClearTokenInformation];
} else {
if (appDelegate.session.state != FBSessionStateCreated) {
appDelegate.session = [[FBSession alloc] initWithPermissions:[NSArray arrayWithObjects:#"email", nil]];
}
[appDelegate.session openWithBehavior:FBSessionLoginBehaviorForcingWebView
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
FBSession.activeSession = session;
[self updateView];
NSLog(#" state=%d",state);
[FBRequestConnection
startForMeWithCompletionHandler:^(FBRequestConnection *connection,
id<FBGraphUser> user,
NSError *error) {
userInfo = #"";
userInfo = user.username;
NSLog(#"string %#", userInfo);
[self checkfacebook];
}];
}]; }
}
FB grants access to your app once the user logs in . If the user wants to modify the privileges he can do it by loggin into fb and changing permissions. You might want to look into oAuth for further details.
As u login through new emailid it has to install your app for them...so,its asking for different login..but again u login with the same it will not ask...the answer for ur 2nd question is....is u doing something to the server side...bcoz there might be a provision on the server which remember user for few hour or few days...so,check with server side..if not working with server...reply me back i will try to answer further...

iOS 6 SDK SLRequest returning '400'

Let me make this clear. I am NOT using the Facebook SDK. I'm using iOS SDK's Social.framework, and ACAccountStore to access Facebook accounts, and post with it/them.
I use the same code to post on Twitter. It works 100%. But for some reason regardless of what I do for Facebook integration, I get a "400" error when I try to post.
My method is:
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *facebookAccountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
// Specify App ID and permissions
NSDictionary *options = #{ ACFacebookAppIdKey: #"MY_APP_ID",ACFacebookPermissionsKey: #[#"publish_stream", #"publish_actions"],ACFacebookAudienceKey: ACFacebookAudienceFriends };
[account requestAccessToAccountsWithType:facebookAccountType options:options
completion:^(BOOL granted, NSError *error)
{
if (granted == YES)
{
NSDictionary *parameters = #{#"message": string999};
NSURL *feedURL = [NSURL URLWithString:#"https://graph.facebook.com/me/feed"];
SLRequest *feedRequest = [SLRequest
requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:feedURL
parameters:parameters];
acct.accountType = facebookAccountType;
// Post the request
[feedRequest setAccount:acct];
// Block handler to manage the response
[feedRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if (granted && error == nil) {
} else {
NSLog(#"Facebook response, HTTP response: %i %#", [urlResponse statusCode], [error description]);
[self closeShareMenu];
}
}];
}
}
I don't know where I'm going wrong! It's so annoying! I've set up my app correctly in Facebook Developers and all! Please help -_-'
Following up to the chat session held between #fguchelaar and yours truly yesterday; I was able to ascertain the following solution for this issue.
Add the following in your iOS completion handler:
NSString *temp = [[NSString alloc] initWithData:data encoding: NSUTF8StringEncoding];
NSLog(temp);
//'data' is your 'responseData' (or another object name) that you declare in your completion handler.
This will allow you to see the exact cause of the issue printed to the Debug Console. Now depending on the issue presented, you'll need to grab a Facebook account from the Array of Accounts generated when you call this handler in the iPhone SDK. Not at any prior stage whatsoever, as the Access Token will likely expire and give you this '400' error.
In my case; the error printed was: error:{'400' A valid access token is required… which vastly annoyed me as my prior method to access and check the current Twitter account was working perfectly. And my theory was that it should work just as well for Facebook. Why should the access token be instantaneously revoked if I'm grabbing the account a split second before?
The way I solved my issue (depending on the reason for your error the answer can vary) was to use a for loop to check the newly created array of accounts, with the sole purpose of finding the account there with the same identifier string as the one I saved into NSData/NSKeyedArchiver.
for(ACAccount *a in arrayOfAccounts) {
if([a.identifier isEqualToString:storedAccount.identifier]) {
//set the account to be used
accountToBeUsed = a;
//don't forget to break the For loop once you have your result.
break;
} else {
//This else{} block is not strictly necessary, but here you could set an account if no account was found with a matching identifier.
}
}
For it to work, it's recommended to declare an ACAccount object in your View Controller's .h file, add a #property and #synthesize it, so it can be assigned within the for loop and used after the break; statement.
This effectively solved my whole issue with the '400' error. It was inexplicably frustrating for about six hours of my day, so I hope that my explanation helps anybody who happens to stumble across this issue, and my question here on Stack Overflow :)
Regards,
cocotutch

SKStoreViewController Sandbox issue

int productID = xxx;
NSDictionary *parameters = #{SKStoreProductParameterITunesItemIdentifier:[NSNumber numberWithInteger:productID]};
[self.storeViewController loadProductWithParameters:parameters
completionBlock:^(BOOL result, NSError *error) {
if (result)
{
[self presentViewController:self.storeViewController animated:YES completion:^{
}];
}
}];
I also created test account on itunes connect and earlier I was able to install this application through test account, but now each time or on other devices I got error. Screenshot attached
The alert view shows that your test was successful. Apple does not let you actually install it since it wants to avoid making app purchases in sandbox mode.

iOS 6 Facebook posting procedure ends up with "remote_app_id does not match stored id" error

I'm trying to perform a simple posting procedure:
- (IBAction)directPostClick:(id)sender {
self.statusLabel.text = #"Waiting for authorization...";
if (self.accountStore == nil) {
self.accountStore = [[ACAccountStore alloc] init];
}
ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSArray * permissions = #[#"publish_stream", #"user_checkins", #"publish_checkins", #"user_likes", #"user_videos"];
NSDictionary * dict = #{ACFacebookAppIdKey : #"My app id here", ACFacebookPermissionsKey : permissions, ACFacebookAudienceKey : ACFacebookAudienceOnlyMe};
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
__block NSString * statusText = nil;
if (granted) {
statusText = #"Logged in";
NSArray * accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
self.facebookAccount = [accounts lastObject];
NSLog(#"account is: %#", self.facebookAccount);
self.statusLabel.text = statusText;
[self postToFeed];
}
else {
self.statusLabel.text = #"Login failed";
NSLog(#"error is: %#", error);
}
}];
}
EDITED:
The problem is that when I click on alertView's OK button (don't allow doesn't work either) nothing happens! - This behavoir now changed with this
iOS 6 Facebook posting procedure ends up with "remote_app_id does not match stored id" So instead of just "nothing happens" I've got an error
"The Facebook server could not fulfill this access request: remote_app_id does not match stored id"
So , it seems that alert view's click handler doing nothing, my completionHandler is never called.
I do have the similar problem already: iOS 6 Social integration - go to settings issue
And I think that it is the same problem here. What do you guys think about it?
P.S.
I'm running on MAC mini, OS X 10.8.1 with latest xcode 4.5 (4G182) and using iPhone 6.0 simulator.
ADDED:
By the Bjorn's request adding the postToFeed method although it is never called:
- (void)postToFeed {
NSDictionary * parameters = #{#"message" : #"Hello world!"};
NSURL * feedUrl = [NSURL URLWithString:#"https://graph.facebook.com/me/feed"];
SLRequest * request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:feedUrl parameters:parameters];
request.account = self.facebookAccount;
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
self.statusLabel.text = #"Posted!";
});
}];
}
I also experienced some difficulties when working with the Accounts Framework and the Facebook integration. Here is what I've learned and how I got it working.
1. Make sure you've setup your App on Facebook correctly
You need to set how your App integrates with Facebook to Native iOS App and enter the Bundle ID of your App into the designated field. (Edit: Note that bundle IDs are case sensitive) You can set the iTunes ID to 0 for now. Enable Facebook Login and set the App Type in the advanced settings tab to Native/Desktop.
Also set App Secret in Client to No.
If one or more of these options are not set correctly it's very likely you get the error The Facebook server could not fulfill this access request: remote_app_id does not match stored id.
(Edit: You also have to ensure the sandbox is disabled.)
2. Installing the Facebook App for the first time
When first installing an App via the native Facebook integration on iOS (and Mac OS X too), you must ask for a basic read permission only! Nothing else as email, user_birthday and user_location is allowed here. Using user_about_me, which is also a basic read permission according to the Facebook documentation, does not work. This is pretty confusing if you previously worked with the Facebook JavaScript SDK or the Facebook PHP SDK, because it asks for the basic permissions by default without you having to do something. Facebook also updated their documentation with a short step-by-step guide on how to use the new Facebook SDK on iOS 6.
3. Requesting additional permissions
It's important to know, that you may not ask for read and write permissions at the same time. That's also something experienced Facebook SDK developers may find confusing. Requesting the read_stream permission along with the publish_stream permission will make the request fail, resulting in the error An app may not aks for read and write permissions at the same time.
As Facebook does not really distinguish between read/write permissions in the Permission Reference, you must identify write permissions by yourself. They're usually prefixed with manage_*, publish_*, create_* or suffixed by *_management.
Facebook does also not recommend to ask for additional permissions immediately after getting basic permissions. The documentation says "You are now required to request read and publish permission separately (and in that order). Most likely, you will request the read permissions for personalization when the app starts and the user first logs in. Later, if appropriate, your app can request publish permissions when it intends to post data to Facebook. [...] Asking for the two types separately also greatly improves the chances that users will grant the publish permissions, since your app will only seek them at the time it needs them, most likely when the user has a stronger intent.".
4. Sample Code
The following sample code should work on iOS and Mac OS X:
ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
// At first, we only ask for the basic read permission
NSArray * permissions = #[#"email"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:#"My app id here", ACFacebookAppIdKey, permissions, ACFacebookPermissionsKey, ACFacebookAudienceOnlyMe, ACFacebookAudienceKey, nil];
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
if (granted && error == nil) {
/**
* The user granted us the basic read permission.
* Now we can ask for more permissions
**/
NSArray *readPermissions = #[#"read_stream", #"read_friendlists"];
[dict setObject:readPermissions forKey: ACFacebookPermissionsKey];
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
if(granted && error == nil) {
/**
* We now should have some read permission
* Now we may ask for write permissions or
* do something else.
**/
} else {
NSLog(#"error is: %#",[error description]);
}
}];
} else {
NSLog(#"error is: %#",[error description]);
}
}];
make sure sandbox mode is not activated if you are trying to access facebook account from application for non developer users.