aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnqi Xu2012-06-23 22:43:14 -0400
committerAnqi Xu2012-06-23 22:43:14 -0400
commit7198316ea93dd6729f3f86d8a1ae2414ce455cd9 (patch)
treec59d1d8b7856067fc4023bf395f725bb8260e0aa
parentc678acdf82f6b3dac4a9fd7bce9f204f8c0afd78 (diff)
downloadLikeFeed-7198316ea93dd6729f3f86d8a1ae2414ce455cd9.tar.bz2
Added Facebook FQL framework
-rw-r--r--Resources/friendship/core/FacebookFQL.js43
-rw-r--r--Resources/friendship/core/core.js7
-rw-r--r--Resources/friendship/friendship.js3
-rw-r--r--Resources/friendship/ui/ApplicationWindow.js18
4 files changed, 69 insertions, 2 deletions
diff --git a/Resources/friendship/core/FacebookFQL.js b/Resources/friendship/core/FacebookFQL.js
new file mode 100644
index 0000000..bd3e96e
--- /dev/null
+++ b/Resources/friendship/core/FacebookFQL.js
@@ -0,0 +1,43 @@
+(function() {
+ fs.core.queryFQL = function(fqlQuery, fqlCallback) {
+ var fqlURL = "fql?q=" + fqlQuery.replace(/ /g, "+");
+ Ti.API.info("https://graph.facebook.com/" + fqlURL);
+ Ti.Facebook.requestWithGraphPath(fqlURL, {}, 'GET', fqlCallback);
+ };
+
+ fs.core.queryAllFriendPostsFQL = function() {
+ var query = "SELECT page_id, name, description, page_url, pic_square, fan_count, type, website, general_info ";
+ query += "FROM page WHERE page_id ";
+ query += "IN (SELECT page_id FROM page_fan WHERE uid ";
+ //query += "= " + Ti.Facebook.uid + ")";
+ query += "IN (SELECT uid2 FROM friend WHERE uid1 = " + Titanium.Facebook.uid + "))";
+ //query += "order by last_name limit 20";
+ Ti.Facebook.request('fql.query', {query: query}, fs.core.handleAllFriendPostsFQL);
+ // TODO: after calling this fn, display the loading animation
+ };
+
+ /*
+ fs.core.handleFQLResponse = function(callback) {
+ };
+ */
+
+ fs.core.handleAllFriendPostsFQL = function(result) {
+ if (result.success) {
+ var postsList = JSON.parse(result.result);
+ Ti.API.fireEvent("processPosts", postsList);
+ /*
+ Ti.API.info(postsList.length);
+ Ti.API.info(postsList[0].name);
+ Ti.API.info(postsList[0].page_id);
+ Ti.API.info(postsList[0].website);
+ */
+ } else if (result.error) {
+ //Ti.API.info("ERROR: " + result.error); // TODO: remove
+ Ti.API.fireEvent("processFQLError", {what:result.error});
+ } else {
+ //Ti.API.info("ERROR: unknown response from FQL query"); // TODO: remove
+ Ti.API.fireEvent("processFQLError", {what:"unknown FQL response"});
+ }
+ }; // TODO: handle timeouts
+
+})();
diff --git a/Resources/friendship/core/core.js b/Resources/friendship/core/core.js
new file mode 100644
index 0000000..dd75086
--- /dev/null
+++ b/Resources/friendship/core/core.js
@@ -0,0 +1,7 @@
+(function() {
+ fs.core = {};
+})();
+
+Ti.include(
+ '/friendship/core/FacebookFQL.js'
+)
diff --git a/Resources/friendship/friendship.js b/Resources/friendship/friendship.js
index 8d3f437..fd61403 100644
--- a/Resources/friendship/friendship.js
+++ b/Resources/friendship/friendship.js
@@ -6,5 +6,6 @@ var fs = {};
Ti.include(
'/friendship/config/config.js',
- '/friendship/ui/ui.js'
+ '/friendship/ui/ui.js',
+ '/friendship/core/core.js'
);
diff --git a/Resources/friendship/ui/ApplicationWindow.js b/Resources/friendship/ui/ApplicationWindow.js
index ff9a9c3..bd2a1d9 100644
--- a/Resources/friendship/ui/ApplicationWindow.js
+++ b/Resources/friendship/ui/ApplicationWindow.js
@@ -1,9 +1,25 @@
(function() {
fs.ui.createApplicationTabGroup = function() {
var tab_group = Ti.UI.createTabGroup();
+
+ var login_button = Ti.Facebook.createLoginButton({
+ top: 50,
+ style: 'wide'
+ });
+
+ var debug_button = Ti.UI.createButton({title: 'Debug'});
+ debug_button.addEventListener('click', function(e) {
+ Ti.API.info('Logged in: ' + JSON.stringify(Ti.Facebook.loggedIn));
+ if (Ti.Facebook.loggedIn) {
+ fs.core.queryAllFriendPostsFQL();
+ }
+ });
+
var win = Ti.UI.createWindow({
title: 'FriendShip',
- tabBarHidden: true
+ tabBarHidden: true,
+ leftNavButton: debug_button,
+ rightNavButton: login_button,
});
var tab = Titanium.UI.createTab({