开发者

Sencha touch and facebook integration?

i am trying to develop an app开发者_开发问答 using sencha touch. Is it possible to integrate facebook into the app? Any sample code would be appreciate.

Thanks


Sencha is a HTML5 framework with mobile event integration. I don't think there is anything in Sencha that allows you to work better with Facebook, I could be wrong, but saying that I would look into http://touch.facebook.com/#!/home.php , it's Facebooks better integrated touch site designed to work with tablets. You may want to integrate to this functionality when working with the framework.

Facebook also has the original mobile site at m.facebook.com


It depends how you want to integrate it I guess, here is how I do it using JSONP. If you sign up for facebook developers and create an app, give it a name and you will be given an App ID and secret key. If you then head over to tools, Graph API explorer you can type in your Facebook page ID number e.g. 509796964 to get an example query. You can find your ID in several ways, just google around a bit.

You will see an access token given at the top. You can then append this to your URL just like any other JSONP call in Sencha, and you will get back results that you can tie to components (for example, I have tied my response to a list).

Here is an example list view:

Ext.define('TCApp.view.FacebookList', {
extend: 'Ext.dataview.List',
 requires: [
    'Ext.plugin.PullRefresh'
],
alias: 'widget.facebooklist',

config: {
    loadingText: 'Loading Movies...',
    plugins: [
        { type: 'pullrefresh' }
    ],
    store: 'Facebook',
    itemTpl: [
    '<div class="wholeitem"><img src="{picture}" class="facebookthumb" />{message}</div>',
    '<div class="smalltext">{description}</div></div>',
    ]
}

});

my store:

Ext.define('TCApp.store.Facebook', {
extend: 'Ext.data.Store',
requires: [
    'TCApp.model.Facebook'
],

config: {
    autoLoad: true,
    model: 'TCApp.model.Facebook',
    storeId: 'Facebook',
    proxy: {
        type: 'jsonp',
        url: 'https://graph.facebook.com/51539791474/feed?access_token=AAAFnhgQ0ZAHIBAO0s9iDUGZAIomBGmLJgpvSE03FmMNSPZAXo35wNKWa0ul0L8Twb9fLsssJTXO0BwthCck5MGViQxbDm0laido30OoYwZDZD',
        reader: {
            type: 'json',
            rootProperty: 'data'
        }
    }
}
});

You have to change the end of the URL token to your own, and it will work, just remember to create a model too with the items you want in your list, for example I have image, text, description and link.

The only thing I can't work out so far is that this access token expires after 2 weeks!!! If you can work out how to request a new token each time it would be awesome, but best in another question I think!

:-)


I haven't try this yet but I guess you will get problem when implement this in a packaged app. Btw, others say that they succeeded with https://github.com/mgcrea/cordova-facebook-connect/ I'll try both solutions and figure it out soon. But this question is old, I don't know if you still need my answer. Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜