9
\$\begingroup\$

I am using LibGDX to create an Android game. I am not making the HTML backend of the game. I just want it to be on the Android Google Play store.

Is it possible to post the scores to Facebook? And if so, how can I do it? I searched and found the solutions only for web-based games.

\$\endgroup\$
  • \$\begingroup\$ To post scores to Facebook, you'll need a network connection. Why not writing a small server side program that processes the data? It seems to me that languages such as PHP are binded by Facebook APIs. Also, if you didn't know it, you can easily pass variables through the URL request of a PHP script. \$\endgroup\$ – guillaume Jul 23 '13 at 8:55
4
\$\begingroup\$

The Facebook APIs are HTTP-based, so you can issue a HTTP post request from your game to the appropriate API endpoint (see "Publish a Post," which unfortunately has no anchor). The endpoint in question is me/feed, so you'll want to construct a request that looks basically like this:

http://graph.facebook.com/me/feed?message="SCORES HERE"&access_token=X

(You'll have to make sure to follow the steps for authentication detailed in the documentation to get the access token you should pass instead of X).

You should be able to use HttpUrlConnection approximately as follows (untested, sortof-pseudocode):

url = new URL("http://graph.facebook.com/me/feed");
connection = (HttpURLConnection) url.openConnection();

// Indicates POST.
connection.setDoOutput(true);

// Encode parameters.
StringBuffer parameters = new StringBuffer();
parameters.append(URLEncoder.encode("message", "UTF-8"));
parameters.append("=");
parameters.append(URLEncoder.encode("\"Score Data Here\"", "UTF-8"));
parameters.append(URLEncoder.encode("access_token, "UTF-8"));
parameters.append("=");
parameters.append(URLEncoder.encode("Access Token Here", "UTF-8"));

// Transmit data.
writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(parameters.toString());
writer.flush();
\$\endgroup\$
0
\$\begingroup\$

Create and host a PHP web service application that, when accessed, takes the scores as HTTP GET argument, performs any needed verification, and then posts them to Facebook using the Facebook API.

PHP is very easy and simple. It will get you up and running in minutes. Use a [WAMP] (http://www.wampserver.com/en/) server if you are using Windows.

You may need to creat a Facebook application from the Apps link in Facebook.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.