user2811941
user2811941

Reputation: 13

Unity3D Facebook SDK Achievements

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.

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.

Upvotes: 1

Views: 2327

Answers (1)

Brian Jew
Brian Jew

Reputation: 906

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);

Upvotes: 2

Related Questions