2012-04-11 69 views
1

我是新來的Facebook發佈,但用一個用戶帳戶脫機發布,但不能發佈離線與公司頁面。Facebook - 如何發佈到使用javascript sdk的公司?

我通過我自己的個人Facebook帳戶創建了自己的「Facebook應用程序」,名爲「尼克斯海報應用程序」。我爲我的個人頁面和公司頁面授予了三個權限(offline_access,read_stream,publish_stream)。 我這樣做按照以下步驟爲每個帳戶...

Creating the app... 
1.  Login to facebook with the account you want linked to the app 
2.  Follow this link http://www.facebook.com/developers/apps.php#!/developers/createapp.php 
3.  Create your app and take a note of you App Id and your App secret Id. 

Giving the correct rights to the app and getting the access_token.. 
Method 1: 
1.  Get the account in question to login to facebook 
2.  However you like, direct the user to this link (replacing <App-Id> with the App Id of the created app) https://graph.facebook.com/oauth/authorize?client_id=<App-Id>&scope=offline_access,read_stream&redirect_uri=http://www.facebook.com/connect/login_success.html 
3.  Take a note of the result of the 「code」 querystring. 
4.  Goto this url (replace 「<APP-ID>」 with you appId and 「<APP-SECRET>」 with your apps secret id and 「<code>」 with the copied code) 
https://graph.facebook.com/oauth/access_token?client_id=<APP-ID>&redirect_uri=http://www.facebook.com/connect/login_success.html&client_secret=<APP-SECRET>&code=<code> 
5.  Copy what you see, minus the expires querystring. That is your access_token. 

後我有我用這個代碼,以使後兩個帳戶的訪問令牌。

<!-- FACEBOOK -->   
<div id="fb-root"></div> 
<script> 
    (function() { 
     var e = document.createElement('script'); 
     // replacing with an older version until FB fixes the cancel-login bug 
     e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; 
     //e.src = 'scripts/all.js'; 
     e.async = true; 
     document.getElementById('fb-root').appendChild(e); 
    }()); 
</script> 
<!-- END-OF-FACEBOOK --> 
<script> 
    //initialise 
    window.fbAsyncInit = function() { 
     FB.init({ 
      appId: '351023398277068', 
      status: true, // check login status 
      cookie: true, // enable cookies to allow the server to access the session 
      xfbml: true, // parse XFBML 
      oauth: true // Enable oauth authentication 
     }); 
    }; 
    function sendPost(inMessage) { 
     var opts = { 
      message: inMessage, 
      access_token: '<SAVED-TOKEN>' 
     }; 

     FB.api('/me/feed', 'post', opts, function (response) { 
      if (!response || response.error) { 
       alert('Posting error occured'); 
      } 
      else { 
       alert('Success - Post ID: ' + response.id); 
      } 
     }); 
    } 

</script> 

當執行與perameter「測試後」的「sendPost」命令,它將對我的個人賬戶工作(提供我把我的access_token到位)。這對我的公司頁面不起作用,並且爲什麼(我把我的acess_token放在適當的位置)不知所措。

Facebok也沒有很好地記錄這一點,它使得很難取得進展,有誰明白爲什麼這不適用於公司頁面?

預先感謝您。

回答

0

您可以設置「到」參數的目標,你想回復,「管理頁面燙髮,將需要如果你想發佈您的網頁到您的網頁應用程序的頁面。

<div id="msg"></div> 
<script> 
// uid is the id of the page or user you wish to post to. 
     function feedthis2(uid) { 

     // calling the API ... 
     var obj = { 
     method: 'feed', 
     to: ''+uid+''  
     }; 

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

     FB.ui(obj, callback); 
     } 
    feedthis2('AnotherFeed'); // to http://facebook.com/anotherfeed 
    //feedthis2('135669679827333'); 
</script> 
+1

我不打算髮布到其他用戶帳戶,只是發表一篇文章到自己的新聞源,或者你說「張貼爲你的頁面頁面」。 什麼是「管理頁面權限」。它與「offline_access 「?目前我唯一的autmmise是」offline_access,read_stream「。我也用過」publish_stream「但沒有任何喜悅。 – user1326989 2012-04-12 09:32:42

+1

好吧,我找到了」manage_pages「權限,現在正在使用我的新access_token。不工作,而且它直到爲我的個人帳戶工作。有任何想法嗎? – user1326989 2012-04-12 09:54:33

+0

對不起,如果我困惑你,作爲頁面張貼到頁面,你需要登錄爲頁面,並獲得頁面訪問令牌。 https://developers.facebook.com/docs/authentication/pages/ 創建一個追加你的頁面acce3ss標記設置帖子作爲頁面id和。那麼你的文章應該可以工作 – 2012-04-12 13:37:25

相關問題