How To make a challenge request in Facebook game - facebook

I'm pretty new in using the facebook SDK.
I have kind of a racin app in facebook and I want to challenge other friends. Also friends which have not installed the app.
I read on the facebook developer page
Match Making
Keep in mind that requests can be sent to any player that has already
installed the game;
But to reach more users I want to send challenge request also to any of my users in my friendlist.
Do I have to send those people which haven't installed the app an app request instead?
Does anybody have some experience with match making games in facebook? Maybe a nice tutorial on the web? The FB Doc for me is very superficial.
Thanks in advance

Import FacebookSDK in your application and Use below code.
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:[NSString stringWithFormat:#"I just smashed %d friends! Can you beat it?", nScore]
title:#"Smashing!" parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if (error)
{
// Case A: Error launching the dialog or sending request.
NSLog(#"Error sending request.");
} else
{
if (result == FBWebDialogResultDialogNotCompleted) {
// Case B: User clicked the "x" icon
NSLog(#"User canceled request.");
} else {
NSLog(#"Request Sent.");
}
}}
friendCache:nil];
}

Related

Facebook share example not working

I followed the set up for my own application. https://developers.facebook.com/docs/ios/getting-started/
I then used the overview example, found here: https://developers.facebook.com/docs/ios/share-dialog/
NSURL* url = [NSURL URLWithString:#"https://developers.facebook.com/"];
[FBDialogs presentShareDialogWithLink:url
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
The share dialog appears, like in the example. I press post and it successfully returns to the app. All looks like its working right? But when I return to the facebook wall and my profile there is no status update. The logs are not displayed so something is going wrong.
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
Any ideas? Facebook redirect you to stackoverflow to get help because they have facebook developers registered.
First, the final part on the first link, about the .plist, is really important. It has to be with the correct info from your app, in order to the share feature to work. Re-check that if you can.
Anyway, the NSLog not printing anything on the console is strange, have you tried searching(command + f) for the message output on the console? Did you try debugging your app and putting breaking points on the 'if' condition to see the state of the error instance?
I don't know if you didn't put it here, or forgot to do it on code, but are you logging the user and checking if the facebook user session is valid? That has to be checked in order for the share to work.
PS: If you are using your facebook App on sandbox mode, any share you do, will only appear on the timeline of the users that are allowed to use the fbApp.

Trouble getting Facebook login and permission request will occur natively in iOS 6 and not fast-app-switch

I am having issues getting the permission request and login to happen natively in iOS, and am currently always getting the fast-app-switch where the authentication happens in a Safari window before switching back to iOS. I have ensured that I logged into Facebook using the Settings app in iPhone Simulator, as well as that I am only requesting read, and not both read and write permissions (in fact my permission array is empty, thus only getting a user's public profile and friend list).
I am using Parse API's PFFacebookUtils, which according to their documentation delegates to the Facebook SDK to authenticate the user.
Here is my code log in code:
- (IBAction)logInFacebook:(UIButton *)sender
{
NSArray *permissionsArray = #[];
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
[self.activityIndicator stopAnimating];
if (!user){
if(!error){
NSLog(#"User cancelled the Facebook login.");
} else {
NSLog(#"Error occured: %#", error);
}
} else if (user.isNew){
NSLog(#"User with facebook just signed up and logged in.");
//Code to move to a new view. Not shown for breveity
} else {
NSLog(#"User with facebook already logged in.");
//Move to new view
}
}];
[self.activityIndicator startAnimating];
}
My question is - is my code causing the old fast-app-switch view to happen, or is some settings in iPhone simulator not done correctly? Thanks!!

iOS: Incorrect/Repetitive Facebook Request Message

I'm using the Facebook SDK and Parse.
I am submitting additional requests for the users email, events, and their friends' events.
Although I receive this info successfully, users who are logged into iOS' facebook system get this popup when I request permissions.
Notice that they are already logged into facebook (via the settings app) and they are simply getting a message to approve the request.
As you can see, it repeats the info about basic profile and friend list (FB login gives you this by default) and doesn't even mention the email. Since I doubt Apple or FB has made this kind of mistake, I assume it has something to do with me. Here is how I request access using FB and Parse.
// The permissions requested from the user
NSArray *permissionsArray = #[ #"email, user_events, friends_events"];
// 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!");
[self.delegate ViewWasDismissed];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
} else {
NSLog(#"User with facebook logged in!");
[self.delegate ViewWasDismissed];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
}];
again, this request WORKS. Therefore, I can't imagine what I could be doing wrong, but the message is strange. Any ideas?
EDIT: I tried deleting my account from the iOS facebook system and requesting directly through the app. This time I got this message:
Notice that here, the user is logged into facebook via the FB app and simply gets this (correct) message to accept permissions.
Is this some kindof bug with Apple's Facebook system?
This is the correct behaviour that will happened for iOS. Since iOS 6, Apple has integrated Facebook to the devices. Therefore, users can log in Facebook from Settings page. Below are the scenario that explain your confusions.
Scenario 1: Logged in to Facebook from Settings page
The app will automatically detect the Facebook account from your device if there's any, and prompt you the permissions request with UIAlertView. This only happen if you're using latest SDK and I am not so sure since which SDK that Facebook released for iOS has this.
Scenario 2: Not logged in to Facebook from Settings page (Old way)
The app will lead you to Facebook app if it's installed in your device. Else it will lead you to Safari with Facebook mobile page open and ask you for permissions that the app required.
Hope this help :)

Is it possible for user of an ios app to like a URL on facebook using the facebook-sdk?

I am creating an iOS app where I want to allow the user to like a specific URL. I've tried to use the following code (as mentioned on the Facebook developers page) to like a specific url:
**- (IBAction)likeClicked:(UIButton *)sender {
SLAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
[FBSession setActiveSession:appDelegate.session];
if (appDelegate.session.isOpen)
{
NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
action[#"object"] = #"http://samples.ogp.me/226075010839791";
[FBRequestConnection startForPostWithGraphPath:#"me/og.likes"
graphObject:action
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
NSLog(#"Error %#",error.localizedDescription);
NSLog(#"result %#",result);
// handle the result
}];
}
}**
But the above code only allows me to like the URL if I am authorized as an admin of that app on the facebook developer page.
If I am not an admin to the app with that specific app id , I get an error description as following:
Error The operation couldn’t be completed. (com.facebook.sdk error` 5.)
There are different solutions given on Stack Overflow for this but none of them seem to be working for me. I've checked for permissions and I have added the "publish_actions" permission to permissions list.
Is there another reason why i might be getting this error?
Is there another workaround using which i can like a specific URL on facebook?
There would be couple of places to check
- Is your Facebook app under "sandbox mode", if it is you will have to turn it off once you are sure with your development.
If you have just created a FB graph action:
You are required to submit the action through the FB developer console and it usually takes couple days for them to approve, and once approved other users can start using the "like" action.
Until you get the action approved, only the App developers, testers and admins (on the FB developer site) for this particular app would be able to complete the action and see the results on their FB timeline.

facebook login works on iphone simulator but not on iphone device

In my app, I want to take photos from the facebook. so i used facebook ios sdk. i can be able to authorize from the below code:
if (appDelegate.session.isOpen) {
//[appDelegate.session closeAndClearTokenInformation];
[self retrieveAlbums];
} else {
if (appDelegate.session.state != FBSessionStateCreated) {
// Create a new, logged out session.
appDelegate.session = [[FBSession alloc] init];
}
// if the session isn't open, let's open it now and present the login UX to the user
[appDelegate.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// and here we make sure to update our UX according to the new session state
//NSLog(#"%#",session.accessTokenData.accessToken);
[self retrieveAlbums];
}];
It works fine on iphone simulator. But I can't able to login on my iphone 4 device.
When I tried to login it will open a safari and then shows the message Updating.
Then it will redirect without authorization. access token retrieved as nil. So I cant able to retreive images.
Please help me.
EDIT
Thanks for everyone .Finally I solved my problem. It is because i enabled sandbox mode in facebook developer account settings. When i disabled the sandbox mode, it works normally.
Try clearing the cookies and cache of your safari, going to Settings.
Also if you do not want the app to redirect to Safari, just dont provide the URL Scheme in your info.plist that is something like "fb-AppId-" and it will open a popup for login
I was having the similar problem and solved it by composing couple of solutions in this website. First of all I got rid of the url scheme at my info plist. So now my app opens up the facebook login dialog inside my registration page. Which is a good thing because it doesn't go back and forth to safari for facebook authentication and you stay inside the app. The second thing I made is, putting an error handling mechanism inside my code for facebook login. So if login with facebook fails, it uses another strategy for logging in.
Here is my code.
- (void)loginView:(FBLoginView *)loginView handleError:(NSError *)error {
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"public_profile", #"user_friends", #"email",
nil];
FBSession *session = [[FBSession alloc] initWithPermissions:permissions];
[FBSession setActiveSession:session];
[self openSessionWithAllowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (!error && status == FBSessionStateOpen) {
NSString *token = session.accessTokenData.accessToken;
NSLog(#"Logged in! - Token -- %#", token);
} else {
NSLog(#"Something wrong happened");//you can check the error code here
}
}];
}