此為facebook 同步處理的方式,要先在facebook網路上建立app,取得appid才行使用


將以下內容放在<body>中

<div id="fb-root"></div>

<script>

Ext.ns('faceBook');
faceBook.message = '';
faceBook.link = '';
faceBook.name = '';
faceBook.picture = '';
faceBook.description = '';
window.fbAsyncInit = function() {
FB.init({
appId: '103570936447553',
status: true,
cookie: true,
xfbml: true});

/* All the events registered */
FB.Event.subscribe('auth.login', function(response) {
// do something with response
login();
});
FB.Event.subscribe('auth.logout', function(response) {
// do something with response
logout();
});

FB.getLoginStatus(function(response) {
if (response.session) {
// logged in and connected user, someone you know
login();
}
});
};
(function() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js#appId=103570936447553&amp;xfbml=1';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
function fb_login(){
console.log('fb-login');

_D('message:'+faceBook.message);
_D('link:'+faceBook.link);
_D('name:'+faceBook.name);
_D('picture:'+faceBook.picture);
_D('description:'+faceBook.description);

FB.login(function(response) {

if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
//console.log(response); // dump complete info
access_token = response.authResponse.accessToken; //get access token
user_id = response.authResponse.userID; //get FB UID

FB.api('/me', function(response) {
user_email = response.email; //get user email
// you can store this data into your database
postonwall();
});

} else {
//user hit cancel button
console.log('User cancelled login or did not fully authorize.');
alert('User cancelled login or did not fully authorize.');
}
}, {
scope: 'publish_stream,email'
});
}
function logout(){
//document.getElementById('fb-root').style.display = "none";
}
function postonwall()
{
console.log('postonwall');

_D('message:'+faceBook.message);
_D('link:'+faceBook.link);
_D('name:'+faceBook.name);
_D('picture:'+faceBook.picture);
_D('description:'+faceBook.description);

FB.api('/me/feed', 'post',
{
message: faceBook.message,
link: faceBook.link,
name: faceBook.name,
picture: faceBook.picture,
description: faceBook.description
}, function(response) {
if (!response || response.error) {
//alert('Oops! User Denied Access');
} else {
//alert('Success: Content Published');
}
});
}

</script>


xxx.js
設定facebook會需要用到的屬性值
//set facebook value
faceBook.message = fs.name;
faceBook.link = 'http://www.nas.com/';
faceBook.name = fs.name;
var findex = fs.imgPath.indexOf('userApps');
var picture = fs.imgPath;
if (findex != -1) {
picture = AS.ARC.config.baseUrl+fs.imgPath.substring(findex, fs.imgPath.length);
}

faceBook.picture = picture;
faceBook.description = fs.description;

, , ,

狼翔月影 發表在 痞客邦 PIXNET 留言(0) 人氣()