I have a very strange behaviours with one user when trying to post. (ipad 2, ios8.3, parse 1.7.4)
(from my device, all ok).
bGranted_publish_actions = always false
bGranted_user_photos = always false
When I call linkUserInBackground, i can see the facebook app opening(very long), and then close directly(not event the time to see the permission screen), and my ios app reopen.
error=nil
succeeded= no
Any idea?
-(void)postShareToFacebookWithDescription:(NSString *)description andBlock:(void (^)(NSError *))completionBlock{
NSLog(#"ℹ️--[%s:%d]",__PRETTY_FUNCTION__,__LINE__);
bool bGranted_publish_actions=[[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"];
bool bGranted_user_photos=[[FBSDKAccessToken currentAccessToken] hasGranted:#"user_photos"];
if (!bGranted_user_photos || !bGranted_publish_actions ){
//withPublishPermissions:#[#"publish_actions", #"user_photos"
[PFFacebookUtils linkUserInBackground:[PFUser currentUser] withPublishPermissions:#[#"publish_actions"] block:^(BOOL succeeded, NSError *error) {
if (succeeded) {
NSLog(#"User now has read and publish permissions!");
[self postDataWithPhoto:nil];
} else {
if (completionBlock) {
completionBlock(error);
}
}
}];
} else {
NSLog(#"Got Facebook publish permissions and about to share");
[self postDataWithPhoto:nil];
}
}
I got my answer:
FBSDKLoginManager logInWithPublishPermissions always returns isCancelled=YES
"This can happen when your Facebook App doesn't have "publish_actions"
permission, or you're not using a test user."
Related
I'm trying to log in with Facebook using Parse.com's PFFacebookUtilsV4. I'm using their standard:
PFFacebookUtils.logInInBackgroundWithReadPermissions(["public_profile"])
{ (user, error) in
When I have connected my FB account to my iPhone in my iPhone's settings. I get an error with code 307 (shown below) every time. If I delete the FB/iPhone account connection from my iPhone's settings, the error goes away and the standard authentication happens. I'm testing on my phone. I have the FB app on my phone, but that doesn't seem to affect the error. Just having it connected via my iPhone's settings.
After digging deeper into the stack trace, I found a different error. This solved it iOS 6 Facebook posting procedure ends up with "remote_app_id does not match stored id"
Just in case anyone has any other errors with login with Facebook on parse here's what I learnt
Add this key to your parse server dashboard FACEBOOK_APP_ID (near where you add MASTER_KEY)
You will have to switch up from the following method
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
to first executing the standard Facebook get token
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions: #[#"public_profile"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(#"Process error");
} else if (result.isCancelled) {
NSLog(#"Cancelled");
} else {
NSLog(#"Logged in");
NSString *facebookUserId = [FBSDKAccessToken currentAccessToken].userID;
NSString *accessToken = [FBSDKAccessToken currentAccessToken].tokenString;
NSDate *expirationDate = [FBSDKAccessToken currentAccessToken].expirationDate;
[self loginFacebookUserWithTokenInfo:facebookUserId
accessToken:accessToken
expirationDate:expirationDate];
}
}];
Then you login using the following section of code
[PFFacebookUtils logInWithFacebookId:facebookId
accessToken:accessToken
expirationDate:expirationDate
block:^(PFUser *user, NSError *error) {
if (error) {
NSLog(#"Error!");
} else {
NSLog(#"User logged in through Facebook and parse!");
// do as you please
}
}];
I implemented the login via Facebook with parse server.
If I use this, I get user information correctly:
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login
logInWithReadPermissions: #[#"public_profile",#"email"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(#"Process error");
} else if (result.isCancelled) {
NSLog(#"Cancelled");
} else {
NSLog(#"Logged in %#",result);
[self fetchUserInfo];
}
}];
but I want to use PFFacebookUtils for easy user creation in Parse:
[PFFacebookUtils logInInBackgroundWithReadPermissions:#[#"public_profile",#"email"] block:^(PFUser *user, NSError *error) {
if (!user) {
//...
} else if (user.isNew) {
//...
} else {
//...
}
}];
The Facebook modal appears with the authorization request, but when I press ok, I get this error:
[Error]: Facebook auth is invalid for this user. (Code: 101, Version: 1.13.0).
Inside the applications settings on Facebook, the app there.
It occurs in Parse app when the user changed Facebook password or removed your app in the applications settings on Facebook.
User.authData should be updated with PFFacebookUtils.logInInBackgroundWithReadPermissions:, but it seems to be not updated. I think that this is problem of Parse Server.
Workaround: When that error occurred, you can update User.authData with PFFacebookUtils.linkUserInBackground:withReadPermissions:.
I downloaded the Parse example AnyPic. I have started looking into it for some ideas for my new app that will use Parse.
When AnyPic first opens up it requires the user to log in with facebook. I have been able to do some testing on the simulator, but now that I have started on the device I cannot log in through facebook. When I try it stays on the log in screen and just changes the log in button to log out. I have stepped through the code and found that the facebook userID is coming back nil. All the other facebook info seems to be returning values.
NSString *accessToken = [[[FBSession activeSession] accessTokenData] accessToken];
NSDate *expirationDate = [[[FBSession activeSession] accessTokenData] expirationDate];
NSString *facebookUserId = [[[FBSession activeSession] accessTokenData] userID];
if (!accessToken || !facebookUserId) {
NSLog(#"Login failure. FB Access Token or user ID does not exist");
return;
}
The facebokUserId comes back nil, while the others have information. I have tried hard coding the facebook user ID to what the simulator gives when it succeeds. This has not worked. I have also tried substituting my own facebook app IDs into the app to see, and it still not work.
I am new with working with social stuff, is there something I'm missing to set up facebook? Or has anyone worked with this example know how to fix it or be able to skip the facebook login?
I ended up remaking a new facebook app ID. I subbed the new info into parse and the app. I also figured out that the wrong facebook account was logged in on the device. Once I logged into the facebook account that made the new facebook app ID it worked right away.
I was having this same issue when running Anypic on a device and submitted a support ticket with Facebook. They confirmed that it's an issue when signing in with the Facebook application and recommended using PFFacebookUtils logInWithPermissions as a workaround until they're able to look into it further. I changed the handleFacebookSession method within PAPLogInViewController.m to the code below and was finally able to login with a device!
- (void)handleFacebookSession {
if ([PFUser currentUser]) {
if (self.delegate && [self.delegate respondsToSelector:#selector(logInViewControllerDidLogUserIn:)]) {
[self.delegate performSelector:#selector(logInViewControllerDidLogUserIn:) withObject:[PFUser currentUser]];
}
return;
}
NSArray *permissionsArray = #[ #"public_profile",
#"user_friends",
#"email"];
self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
// Login PFUser using Facebook
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
if (!user) {
NSString *errorMessage = nil;
if (!error) {
NSLog(#"Uh oh. The user cancelled the Facebook login.");
errorMessage = #"Uh oh. The user cancelled the Facebook login.";
} else {
NSLog(#"Uh oh. An error occurred: %#", error);
errorMessage = [error localizedDescription];
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Log In Error"
message:errorMessage
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:#"Dismiss", nil];
[alert show];
} else {
if (user.isNew) {
NSLog(#"User with facebook signed up and logged in!");
} else {
NSLog(#"User with facebook logged in!");
}
if (!error) {
[self.hud removeFromSuperview];
if (self.delegate) {
if ([self.delegate respondsToSelector:#selector(logInViewControllerDidLogUserIn:)]) {
[self.delegate performSelector:#selector(logInViewControllerDidLogUserIn:) withObject:user];
}
}
} else {
[self cancelLogIn:error];
}
}
}];
}
In my iOS app, I have it so that the user can login using Facebook or Twitter, and it's logging in just fine. The only issue is that every time the user logs out and logs back in, if they try to use Facebook or Twitter it asks them to enter in their information again. Now I know that iOS devices store the users Facebook and Twitter credentials on the phone after they've logged into their account.
So is there a way to log the user into an application using Twitter or Facebook's stored credentials on the phone, and not have to have the user enter their Facebook or Twitter credentials all the time?
Here's what I have so far.
- (NSError *) loginWithFacebook {
NSArray *permissionsArray = #[#"user_about_me", #"user_relationships", #"user_birthday", #"user_location"];
if (![PFUser currentUser] && // Check if a user is cached
![PFFacebookUtils isLinkedWithUser:[PFUser currentUser]]) // Check if user is linked to Facebook
{
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
// Display some sort of loading indicator
if (!user) {
if (!error) {
NSLog(#"The user cancelled the Facebook login.");
[[DEScreenManager sharedManager] stopActivitySpinner];
}
else {
NSLog(#"An error occured: %#", error);
[[DEScreenManager sharedManager] stopActivitySpinner];
}
}
else
{
NSLog(#"User with facebook signed up and logged in");
[[[[DEScreenManager getMainNavigationController] topViewController] view] setHidden:YES];
[[DEScreenManager sharedManager] gotoNextScreen];
[[DEScreenManager sharedManager] stopActivitySpinner];
// Get the Facebook Profile Picture
[self clearUserImageDefaults];
[self getFacebookProfileInformation];
}
}];
}
return nil;
}
- (NSError *) loginWithTwitter {
[PFTwitterUtils logInWithBlock:^(PFUser *user, NSError *error) {
if (!user) {
NSLog(#"Uh oh. The user cancelled the Twitter login.");
[[DEScreenManager sharedManager] stopActivitySpinner];
return;
}
else
{
[[[[DEScreenManager getMainNavigationController] topViewController] view] setHidden:YES];
[[DEScreenManager sharedManager] gotoNextScreen];
[[DEScreenManager sharedManager] stopActivitySpinner];
[[DEScreenManager sharedManager] stopActivitySpinner];
[self getTwitterProfilePicture : [PFTwitterUtils twitter].userId];
[[PFUser currentUser] setUsername:[PFTwitterUtils twitter].screenName];
[[PFUser currentUser] saveInBackground];
[self clearUserImageDefaults];
}
}];
return nil;
}
Thanks in Advance.
You need to check the facebook / Twitter settings in the device global settings app, if the user is logged in there then those details should be used and the user should not be asked to enter anything. If the user isn't logged in there then how the login process works depends on whether the native app is installed or not, and in these cases the device doesn't auto atically get connected to yhe account the user logs into. So you can't really do exactly what you want, because that might not be what the user actually wants.
I am using Parse for my backend on my iOS application, and I am trying to use a FBLoginView to allow users to login with Facebook.
I am also trying to link the user's Facebook account to their Parse account. When I attempt to link the user to their FB by using
if (![PFFacebookUtils isLinkedWithUser:user]) {
[PFFacebookUtils linkUser:user permissions:nil block:^(BOOL succeeded, NSError *error) {
if (succeeded) {
NSLog(#"Woohoo, user logged in with Facebook!");
}
}];
}
I receive an error telling me that the Facebook session is invalid. I have determined that the above code seems to be closing the Facebook session (when I comment out the code, the session does not close) and giving me the error. Does anyone have any experience with this error?
Do your other apps use Parse for the backend?
The user state stored in PFFacebookUtils is different from the user returned from the FBLoginView.
If your code looks like this:
#pragma mark FBLoginViewDelegate {
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user {
// link current user
NSLog(#"User: %#", user);
if (![PFFacebookUtils isLinkedWithUser:user]) {
[PFFacebookUtils linkUser:user permissions:nil block:^(BOOL succeeded, NSError *error) {
if (succeeded) {
NSLog(#"Woohoo, user logged in with Facebook!");
}
}];
}
}
Then you are currently linking a Facebook user object with a PFUser, which are incompatible. I would suggest using the data that the FBLoginView returns, and creating a parse user in the conventional way:
#pragma mark FBLoginViewDelegate {
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user {
// link current user
NSLog(#"User: %#", user);
NSString *username = user[#"email"];
NSString *password = user[#"id"];
[PFUser logInWithUsernameInBackground:username password:password block:^(PFUser *user, NSError *error) {
NSLog(#"User: %#", user);
if (error.code == 101) {
// sign up
PFUser *user = [PFUser user];
user.username = username;
user.password = password;
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
NSLog(#"Error: %#", error);
}];
}
}];
}
Now [PFUser currentUser] will return a parse user object, that was created based on your Facebook login. If the app is deleted/reinstalled, the next time the user enters the app, the FBLoginView will return a userid that will be used to log in to parse as an existing user.
Edit: A similar issue I've had is with using FBLogin, PFFacebookUtils, and any other recent facebook app logins if my phone has Facebook integrated into iOS settings. It seems to have something to do with the Apple integration of Facebook, and the new Facebook SDKs. It's annoying but I have to currently tell my users to delete their facebook information from the Settings, then they can login, using either PFFacebookUtils, or the process above. I hope this gets resolved soon.
for the first part of your question i'd found a way to login user into my app by just using Facebook with Parse. Actually once the users use this, you can check the data browser of your app and check the auth data filed and the profile filed with all the fb data that i did request within the app.
here is the code i use to login with fb, haven't linked a previous user with a fb account
- (IBAction)loginButtonTouchHandler:(id)sender {
// The permissions requested from the user
NSArray *permissionsArray = #[ #"user_about_me", #"user_relationships", #"user_birthday", #"user_location"];
// Login PFUser using Facebook
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
//[_activityIndicator stopAnimating]; // Hide loading indicator
if (!user) {
if (!error) {
NSLog(#"Uh oh. The user cancelled the Facebook login.");
} else {
NSLog(#"Uh oh. An error occurred: %#", error);
}
} else if (user.isNew) {
NSLog(#"User with facebook signed up and logged in!");
//Go to your next view
} else {
NSLog(#"User with facebook logged in!");
//Go to your next view
}
}];
}
Hope this helps!