Unity3D Facebook SDK Achievements - facebook

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.

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

Related

Facebook sdk Unity open graph action does not display

So, I am trying to implement the facebook open graph posts in our game for highscores, but it doesn't seem to post anything. When I do this:
Dictionary<string, string> data = new Dictionary<string,string>() { {"highscore", "http://samples.ogp.me/111111111111111"}};
FB.API("me/namespace:get_a_new", Facebook.HttpMethod.POST, HandleOpenGraphCallback, data);
When I log the FBResult.text in the HandleOpenGraphCallback callback, I get a valid json response looking like this: {"id":"422166374597399"}. But the problem is that I see nothing on the test account that sent that request. The request obviously kind of worked since I receive an id in my callback function, but I see no post. Do I need to put more information in my dictionary in order to even see the post in the my test account timeline? I also put the "publish_action" permission in my login to be sure.
Thank you.

Unity3d Facebook AppRequest filter

In my Unity project for IOS i use
FB.AppRequest(
message: "somedesc",
title: "sometitle",
callback:appRequestCallback );
I want filter and show only friends who don't install app, but filters = ["app_users"] and
excludeIds = "someIdValue" not working
How solved this problem
(I use Facebook Unity SDK, https://developers.facebook.com/docs/unity)
You can use this:
// "app_non_users" will list friends that haven't installed the game yet
List<object> filter = new List<object>() { "app_non_users" };
// Then, call the API with this filter. Enjoy!
FB.AppRequest("Test Message", null, filter, null, 0, string.Empty, string.Empty, this.HandleResult);
In the examples that are provided within the Facebook SDK for Unity, there's a scene called AppRequests. From there, I've seen a class named AppRequests.cs, in which you can find several examples on how to use these app requests.
Note: To try this examples, make sure to add all FacebookSDK provided scenes to your build settings scenes. Test them in device.
FB Unity SDK documentation says that filters are currently supported:
Filter are currently not supported for mobile devices
You should probably get list of friends first with a request like this with FB.API method:
FB.API ("/me/friends?installed=false", HttpMethod.GET, Callback, null);

Access token error when trying to post a Facebook score in a canvas application

I'm trying to integrate the scoring system in my canvas app with Facebook's, implemented using MVC 3 and the 5.2.1.0 Facebook SDK.
A simplified hello-world variant of my game controller looks like:
public class MyController : Controller
{
[CanvasAuthorize("publish_action" /*And some others*/)]
public ActionResult Index()
{
var fb = new FacebookWebClient();
var scores = fb.Get("/me/scores"); // Works (I think)
fb.Post("/me/scores", new { score = 10 }); // Throws an exception
}
}
The call to get scores looks like it's giving me something sensible; the call to write a score value throws "(OAuthException) (#15) This method must be called with an app access_token."
What've I missed? The application id and secret are correctly set in my web.config - for example, I can successfully post an application apprequest in other parts of the actual application not shown in this stripped down test copy. Rummaging around with the debugger shows me that the FacebookWebClient object contains a non-empty access token field, and that that's included in the URI that fb.Post eventually uses.
The Facebook scores page (that Björn links to) mentions only publish_actions but I've tried including other pertinent sounding permissions, such as offline_access and user_games_activity to no effect.
I am assuming that the CanvasAuthorize attribute does the login correctly - it certainly seems to let me send an application apprequest, so it looks as if it's doing the right thing...
Your app needs the permission to write to the users profile. You can use the Graph API to request the required permissions from the user. If granted, Facebook will give you the required access token that you can then use in your request to Facebook. This practice ensures that you only perform actions, the user allowed you to.
Edit_: After looking at the docs: Are you sure you have the required permissions from the user like described here http://developers.facebook.com/docs/score/ ?
Please see this link. You'll need to get an facebook app. Using the apiId and SecretId, you can then post using the information in the link below. The key is adding &scope=manage_pages,offline_access,publish_stream to the url.
like so:
"https://graph.facebook.com/oauth/access_token?client_id={0}&client_secret={1}&grant_type=client_credentials&scope=manage_pages,offline_access,publish_stream";

facebook api in blackberry

Hello friends I am using blackberry facebook sdk but that is not working properly. When I use
their skd that is going right but when I create other file and call api them I have face the problem. Please help me. thanks.
I was face same problem when i was tried to use one feature of local image posting on friends wall,but i resolved it using :
Download graph api from http://sourceforge.net/projects/facebook-bb-sdk/. After that i added two thinks.
one was when i wont to post a photo to your friends wall ,you had to put one more key-value in the JSONObject(Request) - that was requestObject.put("target_id",getid()) in publisePhoto method facebookuser.java & facebook.java
Second was, i had to change JSONObject responseObject = fb.write(getId() + "/photos", requestObject, pPhoto.getMIMEType(), imageData, true);
to
JSONObject responseObject = fb.write(getId() + "/photos?access_token="+Facebook.token, requestObject, pPhoto.getMIMEType(), imageData, true);in FacebookUser.java & Facebook.java
where token is Static string from Facebook.java and store the value of access_token (you have to add it)
I hope that will be helpful to you(Little bit).

Access Facebook albums from a flash app

I want to create a flash Facebook application in which, after pressing a button, the user will be able to browse his/her photo albums and choose a photo. How should i do that? What will be the code under the button to gain authentication from any user using this application?
Thanks.
I am currently writing a facebook application for a university assignment that will allow the user to do everything you can do in facebook, but via the flash player window. You will need a few basic things happening in order to do it.
User log in and authentication - this must be done via Facebook - using OAuth authentication, and meeting all of facebook's security policies
register the application with facebook
Use the Graph API (facebook's developer's toolkit) to get the necessary functions that will communicate with facebook via flash.
In Flash itself you will use a bunch of URLRequest functions to send out to FB for information, then you will need to retrieve that data responses and store them to variables (extracting data with a few lines of code is easy, something like this;
//initialise variables
public var photoURL:String;
var Request:URLRequest = new URLRequest("http://www.whatever the url for the graph api service you are using which is founf from FB");
//that ^^ will send off a request for the url, you then want to use the returned data by registering an event handler like this below
functionName.addEventListener(onComplete, completeHandler);
functionName(event, EVENT)
{
var loader:URLLoader = new URLLoader(Request);
var data:XML = new XMLData(load.loader); //i think this is right but not 100% sure, fiddle with it
//then you want to extract the data that is returned, for example, extracting xml data from a rest request works by hitting data from the xml by specifying a path to the object you want. an example of xml is this <rsp stat="ok"><photos ......more code="morecode"><photo url="url of photo"></photo</photos> so you can hit the url in that example like this;
photoURL = data.photos.photo.#url; //this line will grab the photo url for you, allowing you to dynamically create an array and assign photos to the flash stage according to the url you get
}
this is fairly advanced stuff and I am assuming that you have some decent knowledge on AS3, XML, and the FB API, if you need more help just reply