Hi there,
We're building an app which in part of its functionality tries to capture the number of likes associated to a particular video owned by a user.
Users of the app are asked for extended off-line access and we capture the key for each user:
The format is like this: 2.hg2QQuYeftuHx1R84J1oGg__.XXXX.1272394800-nnnnnn
Each user has their offline / infinite key stored in a table in a DB. The object_id which we're interested in is also stored in the DB.
At a later stage (offline) we try to run a batch job which reads the number of likes for each user's video. (See attached code)
For some reason however, after the first iteration of the loop - which yields the likes correctly, we get a failure with the oh so familiar message:
"Session key is invalid or no longer valid"
Any insight would be most appreciated.
Thanks,
B
List<DVideo> videoList = db.SelectVideos();
foreach (DVideo video in videoList)
{
long userId = 0;
ConnectSession fbSession = new ConnectSession(APPLICATION_KEY, SECRET_KEY);
//session key is attached to the video object for now.
fbSession.SessionKey = video.UserSessionKey;
fbSession.SessionExpires = false;
string fbuid =video.FBUID;
long.TryParse(fbuid, out userId);
if (userId > 0)
{
fbSession.UserId = userId;
fbSession.Login();
Api fbApi = new Facebook.Rest.Api(fbSession);
string xmlQueryResult = fbApi.Fql.Query("SELECT user_id FROM like WHERE object_id = " + video.FBVID);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(new StringReader(xmlQueryResult));
int likesCount = xmlDoc.GetElementsByTagName("user_id").Count;
//Write entry in VideoWallLikes
if (likesCount > 0)
{
db.CountWallLikes(video.ID, likesCount);
}
fbSession.Logout();
}
fbSession = null;
}