{ "id": "60659", "key": "TIMOB-27", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "11213", "name": "Release 0.7.0", "archived": true, "released": true, "releaseDate": "2009-10-05" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2011-04-17T01:50:10.000+0000", "created": "2011-04-15T02:22:41.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [ "facebook", "ios", "iphone" ], "versions": [], "issuelinks": [], "assignee": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2011-04-17T01:50:10.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "{html}

Description

\n

The purpose of this API is to enable developers to use the\nFacebook Connect Objective-C API via Javascript

\n

Create Session

\n

The first step is to create a Facebook Session

\n
\n\nvar session = Titanium.Facebook.createSession({\n    apiKey:'my_api_key',\n    appSecret:'my_app_secret',\n    proxyURL:'my proxy url'\n});\n\nvar isLoggedIn = session.resume();\n
\n

Returns true if user is already logged in, otherwise it returns\nfalse

\n

Button Support

\n

We need to add support for two Facebook iPhone buttons:

\n
\nTitanium.Facebook.CONNECT_BUTTON\n\nTitanium.Facebook.LOGOUT_BUTTON\n
\n

These should be supported via the systemButton property of the\nTitanium.UI.createButton API.

\n

Note: the login button when clicked automatically shows the\nLogin Dialog

\n

Login Dialog

\n

This API creates and displays the Facebook Login Dialog

\n
\n\nvar dialog = Titanium.Facebook.createLoginDialog({\n    session:mySessionObject,\n});\n\ndialog.show();\n
\n

Login Event

\n
\nsession.addEventListener('login',function(session)\n{\n    // returns the updated session object after successful login\n});\n
\n

Permissions Dialog

\n

This API creates and displays the Facebook Extended Permission\nDialog

\n
\nvar dialog = Titanium.Facebook.createPermissionsDialog({\n    permission:'permission_string'\n    success:function()\n    {\n       // permission granted - do something cool\n    },\n    cancel: function()\n    {\n       // permission not granted - too bad\n    }\n});\n\ndialog.show();\n
\n

Generic Facebook API Requests

\n

This API enables you to call any of the support Facebook Connect\nAPIs

\n
\n\nvar requestData = {name:'value',name2:'value2'};\n\nvar request = Titanium.Facebook.executeAPI({\n     name:'api_name',\n     data:requestData,\n     function(result)\n     {\n           // result should be JSON object return from API call\n     }\n\n});\n
\n

Feed Dialog

\n

This API allows you to publish a story to a user's feed.

\n
\n\nvar templateDataObj = {key:'value'};\n\nvar dialog = Titanium.Facebook.createFeedDialog({\n      templateBundleId: 12345,\n      templateData: templateDataObj,\n      function(result)\n      {\n         // was post successful\n      }\n});\n\ndialog.show();\n
{html}", "attachment": [], "flagged": false, "summary": "API - Facebook Connect Integration", "creator": { "name": "nwright", "key": "nwright", "displayName": "Nolan Wright", "active": false, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "nwright", "key": "nwright", "displayName": "Nolan Wright", "active": false, "timeZone": "America/Los_Angeles" }, "environment": null, "comment": { "comments": [ { "id": "122670", "author": { "name": "jhaynie", "key": "jhaynie", "displayName": "Jeff Haynie", "active": false, "timeZone": "America/Los_Angeles" }, "body": "{html}

A few questions:

\n
{html}", "updateAuthor": { "name": "jhaynie", "key": "jhaynie", "displayName": "Jeff Haynie", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:22:41.000+0000", "updated": "2011-04-15T02:22:41.000+0000" }, { "id": "122671", "author": { "name": "mculpepper", "key": "mculpepper", "displayName": "Marshall Culpepper", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Facebook connect (and further OAuth) could be a really killer\nfeature for Desktop as well..

{html}", "updateAuthor": { "name": "mculpepper", "key": "mculpepper", "displayName": "Marshall Culpepper", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:22:41.000+0000", "updated": "2011-04-15T02:22:41.000+0000" }, { "id": "122672", "author": { "name": "jhaynie", "key": "jhaynie", "displayName": "Jeff Haynie", "active": false, "timeZone": "America/Los_Angeles" }, "body": "{html}

I ended up implementing the API a little differently.

\n

Create Login/Logout Button

\n

Create a Facebook login/logout button and bind it to a specific\nID. You can add and remove listeners from this button once\ncreated.

\n
\nvar button = Titanium.Facebook.createLoginButton({\n    'id':'b',\n    'style':'normal',\n    'apikey':Titanium.App.Properties.getString(\"facebook.apikey\"),\n    'secret':Titanium.App.Properties.getString(\"facebook.secret\")\n});\nbutton.addEventListener('login',function()\n{\n    console.info(\"LOGIN\");\n});\nbutton.addEventListener('logout',function()\n{\n    console.info(\"LOGOUT\");\n});\n
\n

The style property can either be normal (default if not\nspecified) or wide.

\n

Query

\n

You can execute FQL query.

\n
\nTitanium.Facebook.query(\"select uid,name from user where uid == \"+Titanium.Facebook.getUserId(),function(r)\n{\n    console.info(\"QUERY RESULT RETURNED success = \"+r.success+\", error = \"+r.error+\", data=\"+r.data);\n});\n
\n

Explicit Login

\n

You can cause explicit login

\n
\nTitanium.Facebook.login(function(result)\n{\n   console.info(\"login success=\"+result.success);\n});\n
\n

Explicit Logout

\n

You can cause explicit logout

\n
\nTitanium.Facebook.logout(function(result)\n{\n   console.info(\"logout success=\"+result.success);\n});\n
\n

Login status

\n

You can determine the login status.

\n
\nTitanium.Facebook.isLoggedIn();\n
\n

Login user id

\n

You can determine the user id of the logged in user or null if\nnot logged in

\n
\nTitanium.Facebook.getUserId();\n
\n

Request extended permission

\n

You can request extend permissions

\n
\nTitanium.Facebook.requestPermission(\"publish_feed\",function(result)\n{\n   console.debug(\"permission success=\"+result.success);\n});\n
\n

Publish to Feed

\n

You can publish to users feed

\n
\nTitanium.Facebook.publishFeed(123456789,{'img':'http://foo/bar.png'},'nolan is cool',function(result)\n{\n   console.debug(\"publish success success=\"+result.success);\n});\n
{html}", "updateAuthor": { "name": "jhaynie", "key": "jhaynie", "displayName": "Jeff Haynie", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:22:42.000+0000", "updated": "2011-04-15T02:22:42.000+0000" }, { "id": "122673", "author": { "name": "jhaynie", "key": "jhaynie", "displayName": "Jeff Haynie", "active": false, "timeZone": "America/Los_Angeles" }, "body": "{html}

(from [6ec20bf4ca21c075ece508f4def5f2c4daa7c86d])\n[#27\nstate:open] added initial Facebook Connect module for iphone\n\nhttp://github.com/appcelerator/titanium_mobile/commit/6ec20bf4ca21c...

{html}", "updateAuthor": { "name": "jhaynie", "key": "jhaynie", "displayName": "Jeff Haynie", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:22:42.000+0000", "updated": "2011-04-15T02:22:42.000+0000" }, { "id": "122674", "author": { "name": "jhaynie", "key": "jhaynie", "displayName": "Jeff Haynie", "active": false, "timeZone": "America/Los_Angeles" }, "body": "{html}

Execute API call

\n

you can execute a facebook method. the 2nd parameter is optional\nand is any data (as javascript json object) to pass to the\nmethod.

\n
\nTitanium.Facebook.execute(\"facebook.Users.getStatus\",null,function(evt)\n{\n   console.info(\"evt = \"+evt+\", success=\"+evt.success+\",cancel=\"+evt.cancel+\",error=\"+evt.error+\",json=\"+Ti._JSON(evt.data));\n});\n
{html}", "updateAuthor": { "name": "jhaynie", "key": "jhaynie", "displayName": "Jeff Haynie", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:22:42.000+0000", "updated": "2011-04-15T02:22:42.000+0000" }, { "id": "122675", "author": { "name": "nwright", "key": "nwright", "displayName": "Nolan Wright", "active": false, "timeZone": "America/Los_Angeles" }, "body": "{html}

added in 0.7.0

{html}", "updateAuthor": { "name": "nwright", "key": "nwright", "displayName": "Nolan Wright", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:22:42.000+0000", "updated": "2011-04-15T02:22:42.000+0000" } ], "maxResults": 6, "total": 6, "startAt": 0 } } }