Home
QFaceBookConnect
Intro
qfacebookconnect is an exact copy (copy/paste) of the facebook connect for iphone. Before you can use qfacebook connect you should study the facebook connect for iphone doc to get the basic idea of how it works.
Download
Go to http://gitorious.org/qfacebookconnect/qfacebookconnect/trees/master
and click on ‘Download master as tar.gz’
or go here: http://gitorious.org/qfacebookconnect/qfacebookconnect/archive-tarball/master
How to use
There is a sample application in the sample/ folder, which can be a good starting point.
Session
The first thing that you need to do is to create a session, like so:
FBSession* session = FBSession::sessionForApplication("<YOUR APP KEY>", "<YOUR APP SECRET>", QString());
The third parameter is for specifying a session proxy, read more about it on facebook developer pages.
The FBSession::sessionForApplication creates a new instance of the FBSession and its your job to delete it.
Once you have a session object, you can connect to the signals you are interested in:
void sessionDidLogin (FBUID aUid);
void sessionDidNotLogin ( );
void sessionWillLogout (FBUID aUid);
void sessionDidLogout ( );
I think these explain themselves pretty well. You can always use the sender() function from QObject to find out who sent the signal.
Unlike the objective-c version of facebook connect, you don’t have to worry about disconnecting signals when u delete your session. Qt will take care of that.
Login
To login to facebook you can use the FBLoginDialog like so:
if (iFBSession->resume() == false)
{
iLoginDialog = new FBLoginDialog();
iLoginDialog->show();
}
The FBSession::resume() function checks if it is possible to restore a previously saved session and thus avoid logging in again, if it is possible the sessionDidLogin() signal will be emitted before it returns true.
How to make a request.
Use the FBRequest::request() static function to get a FBRequest object.
Then use the call method supplying it with the request name and parameters, like so:
FBRequest* request = FBRequest::request();
Dictionary params;
QString query = "select name,pic_big, status,birthday_date, timezone from user where uid in (select uid2 from friend where uid1==" +UserId+ ")";
params["query"] = query;
connect (request, SIGNAL(requestDidLoad(QVariant)), this, SLOT(requestDidLoad(QVariant)));
connect (request, SIGNAL(requestFailedWithFacebookError(FBError)), this, SLOT(requestFailedWithFacebookError(FBError)));
request->call("facebook.fql.query",params);
and then in the sinal metod:
void MainWindow::requestDidLoad(const QVariant& aContainer)
{
if (aContainer.type() == QVariant::List)
{
QVariantList list = aContainer.toList();
for (int i = 0 ; i < list.count(); i ++)
{
QVariantHash dictionary = list.at(i).toHash();
QHashIterator<QString, QVariant> iterator(dictionary);
QString name = dictionary.value("name").toString();
ui->listWidget->addItem(name);
}
sender()->deleteLater(); // delete the request !
}
}
QVariantList, QVariantHash and QVariant
I decided to keep the code simple and therefore I opted to use the QVariants, but as the qt document on QVariant says: “You can even store QList and QMap<QString, QVariant> values in a variant, so you can easily construct arbitrarily complex data structures of arbitrary types. This is very powerful and versatile, but may prove less memory and speed efficient than storing specific types in standard data structures.” QVariant
May be later on this can be improved.
Getting Permissions
Use FBPermissionDialog to do that, read more on the Facebook connect pages on facebook about it.
Well thats all to it.
Please file bug reports on Google Code @ http://code.google.com/p/qfacebookconnect/
Contact me at http://www.greensoftware.net/blog

