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.