Monthly Archives: August 2011

How To Use FQL With The Facebook PHP SDK

Foreword

So the other day while building a Facebook application, I needed to get some information that I just couldn’t find any way to get other than through the use of FQL  Needless to say, finding examples of FQL are plentiful.  However, examples that use FQL and the Facebook PHP SDK are not.  So I thought I’d put one together.

Getting Started

If you haven’t already done so, make sure you’ve installed the latest Facebook SDK and registered your Facebook application.

FQL And The Facebook SDK

Here’s an example call to get all the photos that belong to the logged in user:

$appInfo = array(
'appId' => 'XXXXXXXXXXXXX',
'appSecret' => 'XXXXXXXXXXXXXXXXXXXXX'
); 
 
$facebook = new Facebook($appInfo);
 
$result = $facebook->api( array('method' => 'fql.query', 'query' => 'SELECT src, caption FROM photo WHERE owner=me()') );
foreach($result as $photo){
   ...
}

And there you have it. Hopefully this will save someone the amount of time it took for me to figure it out.

Get Rid of Scrollbars In Facebook IFrame Applications

Foreword

So I was developing a Facebook application and realized that once the content was rendered inside of Facebook, I kept getting scrollbars.  This was terribly annoying being that I wanted to take up more vertical space, but didn’t want the iframe to have scrollbars.  Instead, I wanted the main browser window to have the scrollbars.  Here’s how to get rid of scrollbars in Facebook iframe applications.

Getting Started

First thing you’re going to need to do is modify your application settings under Canvas Settings : On Facebook -> Canvas Settings.

Canvas Settings - On Facebook -> Canvas Settings

Canvas Settings - On Facebook -> Canvas Settings

Once under the Canvas Settings, change the Canvas Width and Canvas Height settings to “Fluid”.

Canvas Settings - Fluid

Canvas Settings - Fluid

Once you’ve done that click “Save Changes” and go to your actual Facebook application code that resides on your server.

The Code

On your side of things, in the actual application that you’re displaying on Facebook, you’ll need to add the following code:

<script src="http://connect.facebook.net/en_US/all.js"></script>
<script language="javascript">
    FB.Canvas.setAutoResize();
</script>

Now go to where you can actually view your application in Facebook and lo and behold…No scrollbars! Yea!…Now go tell your friends at the nerdery how pimp you is.

Browsing The Web Through An SSH Tunnel (Putty / Firefox)

Foreword

I needed a way to get inside my work firewall from home.  There was a DMZ linux machine that I could SSH to, but no VPN available.  What I really needed was a way to configure the router/firewall, but the only way to do that was to be on the internal network and browse to it using a browser.  Trying text based browsers didn’t work, the only way to access and administer the router was to use a full featured browser from behind the firewall itself.  To make a long story short, I figured out how to do it using Putty and Firefox, and this is how you do it.

Getting Started

First things first, make sure you have Putty and Firefox installed.  Next you’ll want to be able to establish an SSH connection to a remote server using Putty.  For example, launch putty, enter the host name or IP and make sure you can connect and login.  Once you have that, you’re ready to setup the SSH tunnel and browse through it.

Configuring The SSH Tunnel

Now open Putty and Enter the hostname or IP of the machine you want to establish a remote connection to.  Next under Connection->SSH->Tunnels find the radio boxes under the Destination field and make sure Dynamic is selected.  Next under where it reads Add new forwarded port: enter a source port.  For this example lets use 1024, enter this in the source port field and click the Add button.  You should see a value in the Forworded ports: list that reads D1024.  That’s all there is to the Putty side of things.  Next go back to the session area and save the current configuration as a saved session if you’d like, then Open the SSH connection.

 

Configure Putty

Configure Putty

 

 

Configuring Firefox

Now, launch Firefox, select Tools->Options and click the Advanced tab. Within the Advanced tab, click on the Network tab and click the Settings button.

 

Network Options

Network Options

 

Within the Network Settings dialog, select the Manual proxy configuration radio button and enter the following for the SOCKS Host: and Port:

SOCKS Host: localhost

SOCKS Port: 1024

 

Connection Settings

Connection Settings

 

Click OK on the Settings dialog, then Click OK on the Options dialog. Now you should be good to go.  Enter a new URL in the Firefox address bar and you’ll be browsing from the remote end of the SSH connection.

Creating Virtual Network Adapters In CentOS

Forward

So here’s the scenario, let’s say for the sake of argument that you have a CentOS linux box running with a single NIC, but you want to have 2 IP addresses assigned to this box (for whatever reason). The following is a step by step guide that will walk you through the process of setting that up.

Getting Started

First, you’ll need to determine the interface name of the network device being used.  For instance, if you’re running a wired ethernet card with a single port, the name is more than likely going to be eth0, if you’re using a wireless card it might be something like wlan0.  First thing you want to do is determine the interface name of this device.  An easy way to do this is to run the following command:

user@computer:$ ifconfig

You should see something similar to the following:

user@computer:$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:3D:2B:AD
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe3d:2bad/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2855541 errors:0 dropped:0 overruns:0 frame:0
TX packets:1205674 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:412143447 (393.0 MiB) TX bytes:539870133 (514.8 MiB)
Interrupt:75 Base address:0x2024

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:4968261 errors:0 dropped:0 overruns:0 frame:0
TX packets:4968261 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2009641198 (1.8 GiB) TX bytes:2009641198 (1.8 GiB)

In this scenario, eth0 is the network interface name and lo is the loopback name.  Now that we know eth0 is the one we want we’ll need to create a virtual device for it (aka. alias).

Create An Network Interface Alias

First, let’s change directory to the network-scripts folder.

user@computer:$ cd /etc/sysconfig/network-scripts/

Next, we’ll copy the ifcfg-<interface_name> to the alias name.

user@computer:$ cp ifcfg-eth0 ifcfg-eth0:0

In this example we are creating a single alias :0 however, you may create as many as you like.  Simply continue to copy the ifcfg-<interface_name> to the desired alias name (ie. ifcfg-eth0:1, ifcfg-eth0:2, etc).

Configure The Alias

Lastly, we need to configure the alias.  This is the step where you physically configure the interface to be static or use DHCP and set the routing information.

For arguments sake let’s configure it to be static.  Open the ifcfg-<interface_name> in the editor of your choice (ie. vi ifcfg-eth0) and set the following.

DEVICE=eth0:0
BOOTPROTO=static
IPADDR=192.168.0.101
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
ONBOOT=yes

Modify each alias configuration file (ie. ifcfg-<interface_name> for each virtual adapter you add) making sure to change the DEVICE, IPADDR, NETMASK and GATEWAY to suit your network.

Once you’ve modified all of the alias configurations for all the aliases you are going to add, restart the network service and you’re good to go.

user@computer:$ service network restart

You can verify that the virtual interfaces are working by pinging each one individually of by running:

user@computer:$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:3D:2B:AD
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe3d:2bad/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2855541 errors:0 dropped:0 overruns:0 frame:0
TX packets:1205674 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:412143447 (393.0 MiB) TX bytes:539870133 (514.8 MiB)
Interrupt:75 Base address:0x2024

eth0:0 Link encap:Ethernet HWaddr 00:25:90:3B:BB:E4
inet addr:192.168.0.101 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:169 Memory:fb5e0000-fb600000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:4968261 errors:0 dropped:0 overruns:0 frame:0
TX packets:4968261 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2009641198 (1.8 GiB) TX bytes:2009641198 (1.8 GiB)