// FBSample logic // This is a helper function that returns an FBGraphObject representing a meal SCOGMeal MealObjectForMeal(String meal) { // We create an FBGraphObject object, but we can treat it as an SCOGMeal with typed // properties, etc. // SCOGMeal result = (SCOGMeal) FBGraphObject.GraphObject(); FBGraphObject obj = FBGraphObject.GraphObject(); SCOGMeal result = new SCOGMeal(obj.Handle); // Give it a URL of sample data that contains the object's name, title, description, and body. // These OG object URLs were created using the edit open graph feature of the graph tool // at https://www.developers.facebook.com/apps/ if (meal == "Cheeseburger") { result.Url = "http://samples.ogp.me/314483151980285"; } else if (meal == "Pizza") { result.Url = "http://samples.ogp.me/314483221980278"; } else if (meal == "Hotdog") { result.Url = "http://samples.ogp.me/314483265313607"; } else if (meal == "Italian") { result.Url = "http://samples.ogp.me/314483348646932"; } else if (meal == "French") { result.Url = "http://samples.ogp.me/314483375313596"; } else if (meal == "Chinese") { result.Url = "http://samples.ogp.me/314483421980258"; } else if (meal == "Thai") { result.Url = "http://samples.ogp.me/314483451980255"; } else if (meal == "Indian") { result.Url = "http://samples.ogp.me/314483491980251"; } return(result); }
// FBSample logic // Creates the Open Graph Action. void PostOpenGraphAction() { // First create the Open Graph meal object for the meal we ate. SCOGMeal mealObject = MealObjectForMeal(selectedMeal); // Now create an Open Graph eat action with the meal, our location, and the people we were with. //SCOGEatMealAction action = (SCOGEatMealAction)FBGraphObject.GraphObject (); FBGraphObject obj = FBGraphObject.GraphObject(); SCOGEatMealAction action = new SCOGEatMealAction(obj.Handle); action.Meal = mealObject; if (selectedPlace != null) { action.Place = selectedPlace; } if (selectedFriends != null) { action.Tags = selectedFriends; } // Create the request and post the action to the "me/fb_sample_scrumps:eat" path. FBRequestConnection.StartForPostWithGraphPath("me/fb_sample_mtscrumps:eat", action, (FBRequestConnection connection, NSObject result, NSError error) => { activityIndicator.StopAnimating(); this.View.UserInteractionEnabled = true; if (error == null) { new UIAlertView("Result", "Posted Open Graph action, id: " + (string)new NSString(result.ValueForKey(new NSString("id")).Handle), null, "Thanks!", null).Show(); selectedMeal = null; selectedPlace = null; selectedFriends = null; selectedPhoto = null; UpdateSelections(); } else { // do we lack permissions here? If so, the application's policy is to reask for the permissions, and if // granted, we will recall this method in order to post the action // TODO: Resolve Status Code 200 if (false) { Console.WriteLine(error.LocalizedDescription); FBSession.ActiveSession.ReauthorizeWithPublishPermissions(new string[] { "publish_actions" }, FBSessionDefaultAudience.Friends, (FBSession fsession, NSError innerError) => { if (innerError == null) { // re-call assuming we now have the permission PostOpenGraphAction(); } else { // If we are here, this means the user has disallowed posting after a retry // which means iOS 6.0 will have turned the app's slider to "off" in the // device settings->Facebook. // You may want to customize the message for your application, since this // string is specifically for iOS 6.0. new UIAlertView("Permission To Post Disallowed", "Use device settings->Facebook to re-enable permission to post.", null, "Ok!", null).Show(); } }); } else { new UIAlertView("Result", "error: domain = " + error.Domain + ", code = " + (FBErrorCode)error.Code, null, "Ok", null).Show(); } } }); }