Feed Post Sample


Facebook APIを使ってFeed Postするサンプル
iphoneのSafariで確認済み

see also

<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
<body>
<div id="fb-root"></div>
<button onClick="loginuser()">login</button>
<div id="user-info"></div>
<img src="xxxxxx">
</body>
</html>
<input type="text" id="memo">
<button onClick="postFeed()">postFeed</button>
<script>

    function postFeed(){
        var obj = {
            method: 'feed',
            redirect_uri: 'http://localhost/feed.html',
            link: 'xxxxx',
            picture:'oooooooo',
            caption:'test',
            description:'testtest'
        };
        FB.ui(obj, function(response){
            console.log(response);
        });
    }

(function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
}(document));

window.fbAsyncInit = function(){
    FB.init({
      appId      : 'ooooooo', // App ID
      channelUrl : '//localhost/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
    });
    FB.Event.subscribe('auth.statusChange', handleStatusChange);
}


function loginuser(){
    FB.login(function(response){
        console.log(response);

    }, {scope: 'publish_actions'});
}

function handleStatusChange(response) {
    console.log(response.authResponse);
  document.body.className = response.authResponse ? 'connected' : 'not_connected';
  if (response.authResponse) {
    console.log(response);

    updateUserInfo(response);
  }
}
function updateUserInfo(response) {
 FB.api('/me', function(response) {
     console.log(response);
   document.getElementById('user-info').innerHTML = '<img src="https://graph.facebook.com/' + response.id + '/picture">' + response.name;
 });
}
</script>