JS端调用Facebook API
1. 申请Facebook账号
2.登陆http://developers.facebook.com/申请APPID
3.一定要对你申请的APP设置Site URL 和Site Domain, 如果你需要调试,可以设置为http://localhost/和localhost
4.在页面中引用JS, <script src="//connect.facebook.net/en_US/all.js"></script>
5.现在就可以调用API了,在调用API之前,必须要进行初始化
调用如下函数进行初始化:
FB.init({ appId: '447540288619439', // App ID channelUrl: 'http://example.com/channel.html', // Channel File status: true, // check login status cookie: true, // enable cookies to allow the server to access the session xfbml: true, // parse XFBML oauth : true });
登陆:
function Test() {// FB.api('/me', function (response) {// alert('Your name is ' + response.name); // }); FB.login(function (response) { if (response.authResponse) { alert('Welcome! Fetching your information.... '); FB.api('/me', function (response) { alert('Good to see you, ' + response.name + '.'); }); } else { alert('User cancelled login or did not fully authorize.'); } }, { scope: 'email,user_location,offline_access,publish_stream' }); }
发布消息:要成功发布消息,必须让APP取得发送权限,注意上面登陆代码中的publish_stream
function PostTest() { var picurl = "http://102.mlsimages.movoto.com/064/12048664_0.jpg"; var body = 'Hello every one, this is my house!'; FB.api('/me/feed', 'post', { message: body, picture:picurl }, function (response) { debugger; if (!response || response.error) { alert('Error occured'); } else { alert('Post ID: ' + response.id); } }); }
其他参数请见:http://developers.facebook.com/docs/reference/api/post/
相关推荐
88274956 2020-11-03
麋鹿麋鹿迷了路 2020-05-29
ThinkingLink 2020-05-20
runner 2020-09-01
梦的天空 2020-08-25
移动开发与培训 2020-08-16
ReunionIsland 2020-08-16
lyqdanang 2020-08-16
MyNameIsXiaoLai 2020-07-08
星辰的笔记 2020-07-04
csstpeixun 2020-06-28
letheashura 2020-06-26
liaoxuewu 2020-06-26
sunzhihaofuture 2020-06-21
FEvivi 2020-06-16
坚持着执着 2020-06-16
waterv 2020-06-14
xiaoge00 2020-06-14
firejq 2020-06-14
firstboy0 2020-06-14
e度空间 2020-06-12
zhongweinan 2020-06-10