Facebook iframe being cut off in Firefox 3.6.x on Mac when using setAutoResize()
Querying Facebook Comment Table with FQL.Query and C#
PowerShell, MySQL Command-Line, and mysqldump Restore Issues

Facebook iframe being cut off in Firefox 3.6.x on Mac when using setAutoResize()

Another day, another Facebook development quirk.

If you’re having issues with your iframe not automatically resizing to full height in Firefox on Mac when using FB.Canvas.setAutoResize, try manually setting the height using FB.Canvas.setSize as in the code below. Obviously, this is only really an option if your know how tall your application will render and it’s the same from page to page or you manually set it on each page.

    <div id="fb-root"></div>    <script type="text/javascript"  src="http://connect.facebook.net/en_US/all.js"></script>    <script type="text/javascript">        FB.init({ appId: '<%= ConfigurationManager.AppSettings["FacebookAppID"] %>', status: true, cookie: true, xfbml: true });        FB.Event.subscribe('auth.sessionChange', function (response) {            if (response.session) {                // A user has logged in, and a new cookie has been saved                            } else {                // The user has logged out, and the cookie has been cleared            }        });

        $(document).ready(function () {            FB.Canvas.setSize({ height: 1100 });        });    </script>

Querying Facebook Comment Table with FQL.Query and C#

Here’s a code snippet for querying the Facebook Comment table using the Facebook C# SDK. Note that this query uses an app signed request, so you’ll get results whether your user is logged in to Facebook or not. This code queries for all comments xids used by your application. If you have more than one like I did, you can then filter through the results to get counts, latest post information, or whatever you need. For more info about the Comment table, read the official documentation.

public void GetFacebookComments()
    var appId = ConfigurationManager.AppSettings["AppID"];
    var appSecret = ConfigurationManager.AppSettings["Secret"];
    // use app signed api key
    FacebookAPI api = new FacebookAPI(appId + "|" + appSecret);

    string url = String.Format("https://api.facebook.com/method/fql.query?query=SELECT fromid, text, id, time, username, xid, object_id FROM comment WHERE xid IN (SELECT xid FROM comments_info WHERE app_id = {0}) ORDER BY time desc&access_token={1}&format=json", appId, api.AccessToken);

    HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
        StreamReader reader = new StreamReader(response.GetResponseStream());
        comments = reader.ReadToEnd();
    JSONObject fbComments = JSONObject.CreateFromString(comments);
    if (fbComments.Array != null)
        String[] xidArray = new String[] { "xid1", "xid2", "etc" };

        foreach (var xid in xidArray) {
            var xidComments = fbComments.Array.Where(m => m.Dictionary["xid"].String == xid);

            if (xidComments != null && xidComments.Count() > 0)
                var lastDiscussBy = xidComments.First().Dictionary["fromid"].String;
                var dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                var lastDiscussTime = dtDateTime.AddSeconds(Convert.ToDouble(chzComments.Last().Dictionary["time"].String)).ToLocalTime();

PowerShell, MySQL Command-Line, and mysqldump Restore Issues

Today’s fun involved trying to restore a mysql dump file. I’m integrating this into an existing process that happens to be a PowerShell script. First, I worked out the appropriate command via the MySQL Command Line Tool to import some data that I needed to work with. The result was that I tried to add something similar to the following into my PowerShell script:

mysql -u root -p[root_password] [database_name] < dumpfile.sql

Running this command in PowerShell, I was given this lovely error message.

The '<' operator is reserved for future use.

I’m not an expert PowerShell coder. I try my hand at it to get things done, but I don’t study it regularly. I pretty much know that if I need to do task A, there’s probably a command for it that I just need to get syntactically correct. I expect to put that command in a window that is supposed to run commands and I expect it to work. Apparently, the ‘<‘ operator is called a “redirection operator” and PowerShell doesn’t support them in this way. I had no concept of “redirection operator” before today. It’s still a fuzzy concept.

In the end, I found two solutions to my problem. One of them was good and one was not. First, here’s what you don’t want to do:

Get-Content dumpfile.sql | mysql -u root -p[root_password] [database_name]

This will cause your entire file to get loaded into an object that can be manipulated in local memory. Fine if you know your file is small, but bad if your file is large. My file is 300+ MB. Instead, try this:

&cmd /c "mysql -u root -p[root_password] [database_name] < dumpfile.sql"

This basically runs this command as though you typed it in the command line. It was much faster.

P.S – Thank you, Luke, for helping me figure this out.

Copyright © 2016, Abby Sims