2010-11-19 16 views
0

ユーザーがリンクをクリックしたときにステータスが表示されるようになりました。 Facebookで初めてログインして権限を受け入れると、ステータスを投稿するようになりました。ユーザーが初めてFacebookにログインしたときのステータス

助けてください!私はログインボタンのためにこのコードを使用しています:

<fb:login-button ></fb:login-button> 

私はFacebook Connectに新しくなっています。

答えて

1

を変更します。

window.fbAsyncInit = function() { 
    FB.init({appId: '<?php echo $this->facebook->getAppId(); ?>', status: true, cookie: true, 
     xfbml: true}); 

    FB.Event.subscribe('auth.login', function() { 
     postStatus(); 
    }); 
}; 
(function() { 
    var e = document.createElement('script'); e.async = true; 
    e.src = document.location.protocol + 
     '//connect.facebook.net/en_US/all.js'; 
    document.getElementById('fb-root').appendChild(e); 
}()); 

function postStatus(){ 
    var body = 'Reading Connect JS documentation'; 
    FB.api('/me/feed', 'post', { message: body }, function(response) { 
     if (!response || response.error) { 
      alert('Error occured'); 
     } else { 
      alert('Post ID: ' + response.id); 
     } 
    }); 

} 

結果:
alt text

EDIT:
また、あなたがpublish_streamあなたのケースで必要な権限を持っていることを確認してください。

<fb:login-button perms="read_stream,publish_stream"></fb:login-button> 
0

ちょうどこのような何かをするだろう、ちょうどauth.loginイベントにご投稿メソッドを呼び出し、あなたはリンクからユーザーとポストを認証するために管理しているので、その後、物事は簡単になります。このコードに

<div id="fb-root"></div> 
<script type="text/javascript"> 
var uid; 
window.fbAsyncInit = function() { 
    FB.init({appId: 'APP_ID', status: true, cookie: true, xfbml: false}); 
}; 
(function() { 
    var e = document.createElement('script'); 
    e.type = 'text/javascript'; 
    e.src = document.location.protocol + 
     '//connect.facebook.net/en_US/all.js'; 
    e.async = true; 
    document.getElementById('fb-root').appendChild(e); 
}()); 
window.fbAsyncInit = function() { 
    FB.init({appId: 'APP_ID', 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 graphStreamPublish(){ 
      var body = document.getElementById("txtTextToPublish").value; 
      FB.api('/me/feed', 'post', { message: body }, function(response) { 
       if (!response || response.error) { 
        alert('Error occured'); 
       } else { 
        alert('Post ID: ' + response.id); 
       } 
      }); 
    } 
    function fqlQuery(){ 
     FB.api('/me', function(response) { 
       var query = FB.Data.query('select name,email,hometown_location, sex, pic_square from user where uid={0}', response.id); 
       query.wait(function(rows) { 
       uid = rows[0].uid; 
       document.getElementById('name').innerHTML = 
        'Your name: ' + rows[0].name + "<br />" + 
        'Your email: ' + rows[0].email + "<br />" + 
        'Your hometown_location: ' + rows[0].hometown_location + "<br />" + 
        'Your sex: ' + rows[0].sex + "<br />" + 
        'Your uid: ' + rows[0].uid + "<br />" + 
        '<img src="' + rows[0].pic_square + '" alt="" />' + "<br />" 
        '<fb:multi-friend-selector actiontext="Select the friends you want to invite. (All of them.)" rows="3"/>'; 
       }); 
     }); 
    } 
    function getFriends(){ 
     var theword = '/me/friends'; 
     var params = new Array(uid); 
     FB.api(theword,params, function(response) { 
      var divInfo = document.getElementById("divInfo"); 
      var friends = response.data; 
      divInfo.innerHTML += '<h1 id="header">Friends</h1><ul id="list">'; 
      for (var i = 0; i < friends.length; i++) { 
      divInfo.innerHTML += friends[i].id+" "+friends[i].name+"<img src=https://graph.facebook.com/"+friends[i].id+"/picture/>"; 
      // divInfo.innerHTML+= '<fb:name useyou=false uid=100001248074891 firstnameonly=true></fb:name>';//'<fb:name useyou=false uid='+friends[i].id+' firstnameonly=true></fb:name>'; 

      } 
      }); 
     } 
    function share(){ 
     var share = { 
      method: 'stream.share', 
      u: document.getElementById('txtShare').value 
     }; 

     FB.ui(share, function(response) { console.log(response); }); 
    }    
</script> 
<fb:login-button 
autologoutlink="true" 
perms="email,user_birthday,status_update,publish_stream"></fb:login-button> 
+0

だけ/ペーストコードをコピーしていない...便利な答えを提供しようとします – ifaour

関連する問題