Question

I am building an iOS app using Appcelerator and the build in Facebook API module. I need to find a way to publish checkin on the behalf of the user. The user must be able to checkin at at location and / or a specific FB page. Is this possible? I can publish status messages but I cannot add a location (place).

Was it helpful?

Solution

It is possible - you need to use Facebook's Graph API, which is accessible the Titanium.Facebook.requestWithGraphPath method. This blog post describes how this is done on iOS, but the workflow is the same - although the author says that Facebook's API has changed recently, so YMMV - I couldn't find any explicit documentation in Facebook's developer resources.

  • To publish a checkin on behalf of the user, you need to have the “publish_checkins” extended permission granted to your app by the user
  • Get the latitude and longitude of your user’s device
  • Find a list of places near the user's location by requesting them from the Graph API
  • Allow the user to pick a place
  • Send a POST request to the Facebook Graph API with path “me/checkins” containing the PlaceID, user coordinates, and optional tags (friend IDs) and a status message

Here's how you'd request the appropriate permission from the user:

Titanium.Facebook.permissions = ['publish_checkins'];
Titanium.Facebook.authorize();

Here's an example URL that you'd use (using Titanium.Network.createHTTPClient to make a GET request) to find a list of places

https://graph.facebook.com/search?q=coffee&type=place&center=37.76,122.427&distance=1000

Then list those places in a table view, and when the user taps one, you POST to create a checkin, assuming you have the ID of the place, and its coordinates, in appropriately named variables:

var data = {
    place: placeID
    coordinates: {
        latitude: latitude,
        longitude: longitude
    }
    message: message,
    tags: [
        // tagged users (optional)
    ]
};


Titanium.Facebook.requestWithGraphPath('me/checkins', data, 'POST', function(e) {
    if (e.success) {
        alert("Success! Returned from FB: " + e.result);
    } else {
        if (e.error) {
            alert(e.error);
        } else {
            alert("Unknown result");
        }
    }
});

You may need to tweak the properties that you send to Facebook if the API has changed, but the general approach is correct.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top