// 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);
        }
Exemple #2
0
        void FQLSample()
        {
            // Query to fetch the active user's friends, limit to 25.
            string query = "SELECT uid, name, pic_big FROM user WHERE uid IN " +
                           "(SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 25)";
            // Set up the query parameter
            var queryParam = NSDictionary.FromObjectAndKey(new NSString(query), new NSString("q"));

            // Make the API request that uses FQL
            FBRequestConnection.StartWithGraphPath("/fql", queryParam, "GET", (connection, result, error) => {
                if (error != null)
                {
                    InvokeOnMainThread(() => new UIAlertView("Error", error.Description, null, "Ok", null).Show());
                }
                else
                {
                    // Here we use an utility method to extract all FBGraphObjects that came from the result
                    var users = FBGraphObject.FromResultObject(result);

                    // We create a RootElement that will hold the list
                    // of people that returned in the result
                    var root = new RootElement("25 Friends")
                    {
                        new Section()
                    };

                    foreach (var usr in users)
                    {
                        root[0].Add(new HtmlElement(usr["name"] as NSString, new NSUrl(usr["pic_big"] as NSString)));
                    }

                    // We create the Dialog View Controller that will display the results and push it.
                    var friendsDialog = new DialogViewController(root, true);
                    NavigationController.PushViewController(friendsDialog, true);
                }
            });
        }
        // 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();
                    }
                }
            });
        }