facebook JavaScript SDK 覚書 - 外部からウォールへの投稿
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
if (window.location.hash.length == 0) {
if (window.location.search.length != 0) {
//ログイン拒否時の処理
} else {
var client_id = 'APP_ID';
if (window.location.hash.length == 0) {
var url = 'https://www.facebook.com/dialog/oauth'
+ '?client_id=' + client_id
+ '&redirect_uri=' + window.location
+ '&response_type=token'
+ '&scope=publish_stream,read_stream'
+ '&display=popup';
location.href = url;
}
}
} else {
if (window.location.search.length != 0) {
//アプリケーションからの投稿拒否持の処理
}
}
</script>
</head>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : 'APP_ID',
status : true,
cookie : true,
xfbml : true
});
function Comment() {
var str = window.location.hash.substring(1);
Data = str.split("&");
atoken = Data[0].replace('access_token=','');
FB.api('me?access_token=' + atoken
, 'get'
, function(response) {
Fsubmit(response.username,atoken);
});
}
function PostMessage(Page_ID,Access_Token) {
var YourMessafes = document.f01.mess.value;
FB.api('/' + Page_ID + '/feed'
, 'post'
, { access_token: Access_Token, message: YourMessages }
, function(response) {
if ( !response || response.error ) {
} else {
//ウォール投稿後の処理
}
});
}
</script>
<form name="f01">
<input type="text" name="mess">
<input type="button" value="comment" onclick="Comment();">
</form>
</body>
</html>