Question

I am trying to post a Facebook story with a map attachement. I can post the story successfully, but the attachement is not shown as map. I am using the Facebook C# SDK (http://facebooksdk.net/).

This is how I set up the story: enter image description here

The custom object is set up with a custom property called geolocation, on which i reffer in the attachement configuration of my story: enter image description here

And this is how I set the parameters for the FB post call:

parameters["location"] = new Dictionary<string, object>();
((Dictionary<string, object>)parameters["location"])["title"] = "Title";
((Dictionary<string, object>)parameters["location"])["geolocation:latitude"] = pokk.Location.Latitude.ToString(CultureInfo.InvariantCulture);
((Dictionary<string, object>)parameters["location"])["geolocation:longitude"] = pokk.Location.Longitude.ToString(CultureInfo.InvariantCulture);

The story is posted successfully, but this is how it looks like: enter image description here

I hope you can help me..

Thanx in advance! Greets!

Was it helpful?

Solution

I have spent the last couple hours trying to diagnose this issue and came up with a solution however the code changes quite abit. Basically the first thing you can do is actually set the property "location" to be required. You will notice that once you set it as required that the Graph API is failing due to a required property missing.

This is a good sign, it means that something is not quite right with the submission. After digging around and manually creating objects in the Object Browser I came up with a solution. Now it is worth noting that I am using dnyamic ExpandoObjects instead of dictionaries but the concept is the same. Review the commented code

//create our location object
dynamic locationData = new ExpandoObject();
locationData.title = "sample app testing " + DateTime.Now.ToString();

//create our geolocation object
dynamic geoData = new ExpandoObject();
geoData.latitude = 37.416382;
geoData.longitude = -122.152659;
geoData.altitude = 42; //<-- important altitude figure

//create our geo data item container and add the geoData object to the geolocation property
dynamic geoDataItem = new ExpandoObject();
geoDataItem.geolocation = geoData;

//set the data property of our location data to the geo data item container
locationData.data = geoDataItem;

//create our root object setting the location property to the location data object
dynamic objItem = new ExpandoObject();
objItem.location = locationData;

var response = context.Client.Post("me/<my_app_name>:<app_action>", objItem);

Really all we are doing is creating a simple structure using the expando object. Where I personally got stuck what not understanding how the complete GeoPoint operates. If you notice we have to create 2 containers.

One container so we can set the geolocation property on the data property of the location object.

The final structure resembles

--- MyStory
    --- location
        --- title : 'Sample app testing....'
        --- data 
            --- geolocation
                --- latitude  : 37.416...
                --- longitude : -122.1526...
                --- altitude  : 42  

This does seem rather complex but here is a final output preview.

enter image description here

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