使用oAuth在sencha touch 2连接Facebook [英] using oAuth in sencha touch 2 to connect facebook

查看:95
本文介绍了使用oAuth在sencha touch 2连接Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我现在不知道如何,至今没有线索。



我们可以在sencha touch中使用facebook javascript sdk吗?



我发现以下教程很好,可以将其与extjs mvc



http://thinkdiff.net/facebook/new-javascript-sdk-oauth-2-0-based-fbconnect-tutorial/

解决方案

取决于你想要连接我想。对我来说,我只需要连接并显示一个Facebook页面的墙上的帖子,就可以在iPad上显示。我做的方式如下:登录到Facebook开发人员并创建一个应用程序。给它一个名字,例如Senchatouch应用程序它将生成一个appID和密钥。



然后,您需要通过查询此链接找到您的Facebook用户名ID:



https://graph.facebook.com/ [用户名]



一旦你有了,那么你必须去Facebook Graph API资源管理器并输入该ID您可以看到一个示例响应。



然后,您需要将访问令牌附加到此链接:



https://graph.facebook.com/51539791474/feed?access_token=ACCESS_TOKEN



所以你有这样的东西:



https://graph.facebook.com/51539791474/feed?access_token=AAAFnhgQ0ZAHIBAAbiopuvZAa8zlEmRyxKtZBTcgspJIJ21tVwI17xZCJEbgtNRaMUCnGBVwUa1zE7s6ZBRzg6r J5UGIEBhZAQfMsCrrT0GVQZDZD



这是您可以在sencha touch 2中使用普通JSONP代理的链接。



我的商店代码:

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

config:{
autoLoad:true,
model:'TCApp.model.Facebook',
storeId:'Facebook',
proxy:{
type:'jsonp',
url:'https: //graph.facebook.com/51539791474/feed?access_token=AAACEdEose0cBAAJt7hcZCdkHHK8hOjZBDFd8GSfg2xkI6hj5AghswWn7MvBTz4B4xooN4t2fXvMmTZCrxAq4t5ofnnPIY7oZBebnbuB5wQZDZD,
读者:{
类型: 'JSON',
rootProperty: '数据'
}
}
}
});

和我的型号:

  Ext.define('TCApp.model.Facebook',{
extends:'Ext.data.Model',
config:{
fields:[
{
name:'message'
},
{
name:'picture'
},
{
name:'链接'
},
{
名称:'description'
}
]
}
});

然后我用这个itemTpl绑定一个简单的列表:

 '< div class =wholeitem>< img src ={picture}class =facebookthumb/> {message} div>',
'< div class =smalltext> {description}< / div>< / div>',

我遇到的唯一问题是到期,似乎每个访问令牌的有效期为2小时。我还没有弄清楚如何扩展它,如果你发现请发布解决方案或链接到它。谢谢



: - )


Aren't there any functions/libraries provided by sencha touch 2 to connect with facebook.

I am clue less so far now

Can we use facebook javascript sdk inside sencha touch ?

I have found following tutorial good , can we merge it with extjs mvc

http://thinkdiff.net/facebook/new-javascript-sdk-oauth-2-0-based-fbconnect-tutorial/

解决方案

Depends how you want to connect I guess. For me, I just needed to connect and display the wall posts of a facebook page to display on my iPad. The way I have done it is as follows: Login to facebook developers and create an app. Give it a name e.g. Senchatouch App. It will generate an appID and secret key.

You then need to find your facebook username id by querying this link:

https://graph.facebook.com/[username]

Once you have that then you have to go to the Facebook Graph API explorer and type that ID in and you can see an example response.

Then you need to append the access token to this link:

https://graph.facebook.com/51539791474/feed?access_token=ACCESS_TOKEN

so you have something like:

https://graph.facebook.com/51539791474/feed?access_token=AAAFnhgQ0ZAHIBAAbiopuvZAa8zlEmRyxKtZBTcgspJIJ21tVwI17xZCJEbgtNRaMUCnGBVwUa1zE7s6ZBRzg6rJ5UGIEBhZAQfMsCrrT0GVQZDZD

This is the link you can use in a normal JSONP proxy in sencha touch 2.

My store code:

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=AAACEdEose0cBAAJt7hcZCdkHHK8hOjZBDFd8GSfg2xkI6hj5AghswWn7MvBTz4B4xooN4t2fXvMmTZCrxAq4t5ofnnPIY7oZBebnbuB5wQZDZD',
        reader: {
            type: 'json',
            rootProperty: 'data'
        }
    }
}
});

and my model:

Ext.define('TCApp.model.Facebook', {
extend: 'Ext.data.Model',
config: {
    fields: [
        {
            name: 'message'
        },
        {
            name: 'picture'
        },
        {
            name: 'link'
        },
        {
            name: 'description'
        }
    ]
}
});

I then bind this to a simple list using this itemTpl:

'<div class="wholeitem"><img src="{picture}" class="facebookthumb" />{message}</div>',
    '<div class="smalltext">{description}</div></div>',

The only problem I am having is the expiry, it seems each access token has an expiry of 2 hours. I haven't worked out how to extend it yet, if you find out please post the solution or link to it. Thanks

:-)

这篇关于使用oAuth在sencha touch 2连接Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆