FacebookScorer – Post highscores to user’s Facebook Wall

Today’s post is an update for an old article about posting high scores to Facebook Wall. Some users have reported some issues about this class. There were some problems with the state control when authorization was needed.

Today I will like to post a new version of the class that solves these issues. The project is now called FacebookScorer and you can find it on GitHub.

Facebook icon_big

With FacebookScorer you can post scores for your game on Facebook Wall on user’s behalf in a single line of code.

Facebook Post

Features

FacebookScorer offers the following features:

  • Publish scores to Facebook Wall with the Facebook Dialog
  • Handles automatically login and authorize on Facebook

Deployment

1 – Add the FacebookScorer folder to your Xcode project.

2 – Add the following methods to your app Delegate: (remember to include FacebookScorer.h)

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return [[[FacebookScorer sharedInstance] facebook] handleOpenURL:url];
}

// For 4.2+ support
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [[[FacebookScorer sharedInstance] facebook] handleOpenURL:url];
}

3 – Add “URL Types” array as shown on the image below to your Info.plist file. You will need to introduce your Facebook’s app ID in the “URL identifier” and “URL Schemes” fields. Notice the “fb” prefix in “URL Schemes”.

plist Facebook

Usage

There is a simple Demo app within the project.

On top of the FacebookScorer.m file you will find the constants to be customized, including your Facebook app ID:

static NSString* kAppId = @"000000000000000"; // Your Facebook app ID here

#define kAppName        @"Your App's name"
#define kCustomMessage  @"I just got a score of %d in %@, an iPhone/iPod Touch game by me!"
#define kServerLink     @"http://indiedevstories.com"
#define kImageSrc       @"http://refractedpixel.com/indiedevstories/wp-content/uploads/2011/08/newsokoban_icon.png"

Then, simply add this line of code where you want the Facebook dialog to appear:

[[FacebookScorer sharedInstance] postToWallWithDialogNewHighscore:123];

Done! As usual, very easy to use 😉

HTH!

61 thoughts on “FacebookScorer – Post highscores to user’s Facebook Wall

  1. Pingback: List of Open Source Cocos2d Projects, Extensions and Code Snippets | iUridium

  2. I got the FB app popup but then it logs me out from FB app. Also if I want the dialog stay in my game, what should I do?

  3. Hi Toni and thanks for sharing!
    I have tried to use your demo app but after it launches FB add user accept the app it does not post the message and return to the app. instead it stays in FB. In fact I do not get any callback as a result of this: [_facebook requestWithGraphPath:@”me” andDelegate:self];

    Any ideas what I’m doing wrong?
    Where should I add the FB app secret? Currently I have only added FB app id in the FacebookScorer.m and in the plist file URS Scheme. What should I add in the URL identifier?

  4. @Tommy,

    I have just re-read your previous comment and saw that you asked: ” What should I add in the URL identifier?”

    Do you mean in the plist file? If so, it is again the app ID. You need to insert the app ID twice in the plist file. In the URL Identifier field without the “fb” prefix.

    HTH

  5. Thank you, it was a success, just one more thing, there is a way to the users log out of the facebook and uses another account to post on his wall ???

    Thank you!!

    • I have a new problem Toni, when i run the app on the simulator on the mac, it works good, but when i run on the device, it does not work, the facebook opens my facebook`s timeline and not the “window” to post high score.

    • Hi Tony. Good Job!! I have a problem. I do:

      [[[FacebookScorer sharedInstance] facebook] logout];

      But when I wan’t to share with other user I share with the same user that I used before.

      I don’t know why.

      Sorry for my english!

    • Hi Toni,

      Thxs again for this code really useful, I would like to do “logout” function, I use as you said “[[[FacebookScorer sharedInstance] facebook] logout];” , it logout properly but after I am not able to find back the user access window of Facebook with userName, password, any idea ?, thxs a lot I will appreciate

      • Ok I understand better my issue , actually when I launch FaceBook logout instructions, after I need to go to safari settings and press “Clear cookies and token” in order to find back the identification window of Facebook, do I need to add something else to clear cookies/datas in your code, thxs a lot ?!

  6. Great tutorial and library! I managed to get the demo working and post to my Facebook page. When I try to implement the code in my own iPhone app I get a whole stack of errors about “‘release’ is unavailable in automatic reference counting mode”, “ARC forbids explicit message send of ‘release'”, etc. I am using the latest iPhone 5.1 SDK with XCode 4.3.1. Any suggestions?

  7. Wow thanks! Really works out of the box.
    I just made a minor mistake by entering the fb000 into the field where it shouldn’t have a prefix.

    Thanks a lot!

  8. Thanks for the code, so simple to use. But I have a problem. Everytime I tap the button in my app to post to the wall, it will launch the facebook app (or Safari in the simulator) and displays the line “An error occurred. Please try again later”. When I tap the “okay” button, it will load facebook but without the wall posting. Any thoughts?

    • Ensure you have added your facebook app ID both in “FacebookScorer.m” and “Info.plist”.

      Also ensure that you have added these methods to your app delegate:

      – (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
      return [[[FacebookScorer sharedInstance] facebook] handleOpenURL:url];
      }

      // For 4.2+ support
      – (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
      return [[[FacebookScorer sharedInstance] facebook] handleOpenURL:url];
      }

      HTH

      • Thanks that helped, I also realised I made a mistake by adding the app name instead of the app ID, so that’s settled. But what about posting a picture? I passed the name of a picture (e.g. @”Image1.png”) to FacebookScorer but it’s not appearing on the wall. Are images meant to be grabbed from a server?

        • This version of FacebookScorer is designed only to post messages to the wall with a pre-defined image in the message that must be on a server.

          If you want to upload images to a user Facebook album you will need to try a different solution. FacebookScorer won’t help.

          HTH

  9. Hello:

    I have been using your FBScorer and really like it. But I do have a slight challenge. The first time that a user launches the app and it asks to authorize it when you press ok to authorize in the simulator it says that Safari can’t open the page. On the device Facebook crashes. Then once you reload the app then it is fine. Please advise.

    • Make sure you have added your facebook app ID both in “FacebookScorer.m” and “Info.plist”.

      Also ensure that you have added these methods to your app delegate:

      – (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
      return [[[FacebookScorer sharedInstance] facebook] handleOpenURL:url];
      }

      // For 4.2+ support
      – (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
      return [[[FacebookScorer sharedInstance] facebook] handleOpenURL:url];
      }

      HTH

      • That worked. I had the info.plist file set up incorrectly. Thanks for the quick response! Do you plan on modifying the class so that you can have upload a local image rather than a server based image?

        • Unfortunately it is out of the scope of this simple class. FBScorer was designed to be extremely simple and easy to use.

          Allow for image upload would break this so simple design and would make no sense.

          However, the code to upload an image with the Facebook API is not hard. But it is difficult to encapsulate in a neat way in a Singleton.

          Sorry.

  10. Hi.. where would I find instructions on how to obtain a “facebook app ID”? Does it have to be an actual app? (as in, does it have to be any code or functionality on facebook’s side?) thanks.

  11. Hi there 🙂

    Thanks for this amazing piece of code.

    I’m using it in my app but when I tap the button in my app to post to the wall, it will launch the facebook app then switch to my app and do nothing except the method fbDidNotLogin.

    Although I have set the App ID in the FBScorer.m and info.plist (twice, one with the prefix).

    I’m wondering where i messed up. please a little hint 🙂

  12. hi Toni, thanks for the useful facebookscorer class. I’ll include your name in my game too. BTW is there a way to just post to the wall without the dialog box? like an auto wall post, i just don’t want to break the flow of the game but want to post game progress to facebook wall. thanks again.

    • It has been a long time since the last time I red the iOS Facebook API, but have a look at the method called “requestForPostStatusUpdate:” from the FBRequest class.

      I think it is just what are you looking for.

      HTH!

  13. Hi, i just pasted the code in and pasted in the FB App ID’s to the URL like you show in your example. However when i run in the simulator it builds, but then when i click on the button to post to FB the simulator quits and the error log states MISSING AP ID!!! any idea why this is happening? thanks.

    -Brett

Leave a Reply to Nnob Cancel reply