Sample Code not working

Nov 11, 2008 at 10:32 PM

So, I've just downloaded and installed the Facebook Developer Toolkit on my Virtual Studio. However, the sample code doesn't seem to work. The program seems to run fine, but I end up with an empty list and, therefore, no printout. It's hard to diagnose because I don't get an error message.

Any body out there experienced the same and solved it? I'm going nuts here...

This is what code I'm looking at: (I had to slightly modify the sample code to get it to run)

using System;
using System.Text;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using facebook;

namespace facebooktest
class Program
private const string apikey = "f46138a4-My-Key-bea1b9f88f5";
private const string apisecret = "83d70e193ef-My-Secret-580d4";

static void Main(string[] args)
facebook.Components.FacebookService _fbService = new facebook.Components.FacebookService();
_fbService.ApplicationKey = apikey;
_fbService.Secret = apisecret;

// GetFriends() stores all User attributes in a Collection
IList<long> friends = _fbService.friends.getAppUsers(); // this will automatically trigger _fbService.ConnectToFacebook()
foreach (long u in friends)

Nov 11, 2008 at 11:05 PM
I think that's a legitimate result: GetAppUsers should return the friends of the current user who have authorized the current application. So if none of the current user's friends have authorized the app, you should get an empty list back. If you're just looking for a list of the user's friends, try friends.get.
Nov 11, 2008 at 11:24 PM

Thanks jschuster! Quick answer!

I had to add the line:

_fbService.uid = "<MyUID>";

And then call the _fbService.friends.get() method. That gives me a "Session key invalid or no longer valid"-error, but I'm on to somthing here :)

I am now able to extract myself from facebook using the method:

facebook.Schema.user me = _fbService.users.getInfo();

Nov 12, 2008 at 3:44 AM
Usually that "Session key invalid" error means you haven't properly connected to Facebook for the current session, or there's some sort of permissions issue. Other people who have run into that might be able to tell you more. Keep digging into it; I think you're on the right track.