2012-01-17 19 views
0

私は自分のアプリのための壁紙の機能をFacebookのポストを開発しています。私はFacebook Javascript SDKを使用しています。しかし、事は私がリンクをクリックしてpostToFeed()関数を呼び出すとき、それは完全にiframeで動作します。しかし、別の方法(body onloadなど)でロードしたい場合、iframeにエラー "エラーが発生しました。後でやり直してください"と表示されます。私はaccess_tokenにFB.uiを提供してセッションの問題を取り除いていますが、それでもリンクをクリックすることなく動作させるわけではありません。以下は私のコードです:Facebook post to wall to work to work

<div id='fb-root'></div> 
    <script src='http://connect.facebook.net/en_US/all.js'></script> 
    <p><a onclick='postToFeed(); return false;'>Post to Feed</a></p> 
    <p id='msg'></p> 
    <?php 
    $token_url = "https://graph.facebook.com/oauth/access_token?client_id=MY_CLIENT_ID&client_secret=MY_CLIENT_SECRET&grant_type=client_credentials&redirect_uri=MY_REDIRECT_URI"; 
    $token = file_get_contents($token_url); 

     ?> 

    <script> 
    FB.init({appId: "MY_APP_ID", status: true, cookie: true}); 

    function postToFeed() { 

    // calling the API ... 
    var obj = { 
     method: 'stream.publish', 
     display: 'iframe', 
     access_token: '<?php echo $token;?>', 
     link: 'https://developers.facebook.com/docs/reference/dialogs/', 
     picture: 'http://fbrell.com/f8.jpg', 
     name: 'Facebook Dialogs', 
     caption: 'Reference Documentation', 
     description: 'Using Dialogs to interact with users.' 
    }; 

    function callback(response) { 
     document.getElementById('msg').innerHTML = "Post ID: " + response['post_id']; 
    } 

    FB.ui(obj, callback); 
    } 

</script> 

私のアプリは現在サンドボックスモードです。しかし、私はそれが問題ではないと思います。これで私を助けてください。ありがとう

答えて

1

あなたの方法は間違っているようです。あなたはFacebookからの最新の例を使用していないかもしれません。参照:https://developers.facebook.com/docs/reference/dialogs/feed/

// calling the API ... 
var obj = { 
    method: 'feed', 
    link: 'https://developers.facebook.com/docs/reference/dialogs/', 
    picture: 'http://fbrell.com/f8.jpg', 
    name: 'Facebook Dialogs', 
    caption: 'Reference Documentation', 
    description: 'Using Dialogs to interact with users.' 
}; 

function callback(response) { 
    if (response && response.post_id) { 
    document.getElementById('msg').innerHTML = "Post ID: " + response.post_id; 
    } else { 
    alert('Post was not published.'); 
    }  
} 

FB.ui(obj, callback); 
+0

ご返信ありがとうございます。私はそれを整理しています.... :) –

+0

あなたはそれが整理されているので、この質問を閉じることができますか? – DMCS

+0

どこからこれを閉じることができますか? –