1

I'm trying to implement achievements with the Facebook Unity SDK.

I was hoping somebody could give me a qualitative description of the process required to do this.

Here's what I've done so far.

  • Hosted the web build on a server
  • Created an achievements folder on this site and created a test achievements html file as in https://developers.facebook.com/blog/post/539/

    My main confusion is the difference between registering an achievement and positing an achievement.

Is registering an achievement something that needs to be done only once and if so where should this be done? Do I need to create a script in unity that registers all the achievements for the game that I run before the rest of my testing? Also I'm unsure how the method call works for registering and posting an achievement. I'm under the impression I need to call FB.API(string endpoint,Facebook.HttpMethod,FacebookDelegate callback,Dictionary formData)

but I'm really not sure what the input arguments need to be.

Here's my attempt so far(I'm pretty sure the string endpoint I've used is wrong)

private void RegisterAchievement()
{
    string achievement ="http://www.invadingspaces.com/unity/testing/Achievements/ach1.html";
    string appID = "999408935255000";
    string achievement_display_order = "1"; 

    string achievement_registration_URL = "https://graph.facebook.com/"+ appID + "/achievements";
    FB.API(achievement_registration_URL+","+"achievement="+ achievement+ "&display_order=" +achievement_display_order+ "&access_token=" + FB.AccessToken ,Facebook.HttpMethod.POST,null,null);
}

Thanks in advance.

1 Answers1

2

I'd suggest looking at the general Facebook achievements API: https://developers.facebook.com/docs/games/achievements/

Also you can first test out what to actually put with the graph explorer then put that into graph.: https://developers.facebook.com/tools/explorer

So for example to create a new achivement it's just this:

var dict = new Dictionary<string,string>();
dict["achievement"] = "<URL_TO ACHIEVEMENT_HERE>";
FB.API(FB.AppId+"/achievements", Facebook.HttpMethod.POST, null, dict);

To get all your game achievements, it's:

FB.API(FB.AppId+"/achievements", Facebook.HttpMethod.GET);

Then to award a player an achievement, it's just this:

var dict = new Dictionary<string,string>();
dict["achievement"] = "<URL_TO ACHIEVEMENT_HERE>";
FB.API(FB.UserId+"/achievements", Facebook.HttpMethod.POST, null, dict);

To get that player's achievment that they completed, it's:

FB.API(FB.UserId+"/achievements", Facebook.HttpMethod.GET);
Brian Jew
  • 906
  • 5
  • 5
  • Thanks Brian your post is massively helpful. I've read the Achievements API but I'm still unclear as to the role of creating achievements. Surely this is something that doesn't need to be done by the user. Surely I create achievements for the app once and the user's client just grabs the dictionary of available achievements and sets the relevant one to be completed? Also I notice you work at Facebook. Do you know if there are plans to introduce achievement progress in the near future? I'm working on porting our game to webplayer on facebook on iOS and some of our achievements are incremental. – user2811941 Sep 25 '13 at 09:12
  • Also, you say to get the achievements a player has completed it's FB.API(FB.AppId+"/achievements", Facebook.HttpMethod.GET); however FB.API has no return type. How do I get at the achievements the player has completed? – user2811941 Sep 25 '13 at 15:37
  • Creating the achievement should be done from the server side hitting the graph endpoint directly and should not be done by the user. You are correct. You can grab the list of achievements then set the relevant ones as complete. Also I don't know anything more about any plans about achievements than what's documented. FB.API takes in a delegate just like everything else in the SDK. Use that delegate which will give you a FBResult. That will get you what you need – Brian Jew Sep 30 '13 at 17:27
  • If there are still doubts on how to do this, I wrote a post on my blog about how to achieve this: http://bigfootgaming.net/blog/integrating-facebook-achievements-in-unity3d/ – Gaston Claret May 10 '14 at 23:04