2012-04-13 15 views
0

所以這就是我想要做的。我創建了我的Facebook應用程序,並且可以使用Graph API瀏覽器在右上角指定應用程序。如何獲取應用程序的Facebook訪問令牌以在公司隔離牆上發佈?

一些更詳細的信息,我正在使用C#在我們的內部應用程序的功能中編寫代碼以使其工作。

之後,我轉到url部分並輸入以下地址。

https://graph.facebook.com/MyCompanyPage

然後點擊提交。它將在瀏覽器中瀏覽並顯示下面的頁面信息。那麼爲了讓我的access_token爲我的應用程序,我去了,然後點擊Get Access Token - >指定我的擴展權限 - >然後再次點擊Get Access Token。所有這一切都很好,我可以成功地使用我們的Facebook應用程序發佈到Facebook。

問題是,access_token過期了,我正在使用手動檢索方法來獲取訪問令牌。

以下是我嘗試使用GIT的一個示例做的事情。

FacebookClient client = new FacebookClient(); 
dynamic parameters = new ExpandoObject(); 
parameters.client_id = "MYAPPID"; // Or does this need to be my CompanyPage ID?? 
parameters.redirect_uri = "https://www.facebook.com/connect/login_success.html"; 
// The requested response: an access token (token), an authorization code (code), or both (code token). 
parameters.response_type = "token"; 
// list of additional display modes can be found at http://developers.facebook.com/docs/reference/dialogs/#display 
parameters.display = "popup"; 
// add the 'scope' parameter only if we have extendedPermissions. 
parameters.scope = "publish_stream,manage_pages,status_update"; 
// when the Form is loaded navigate to the login url. 
Uri LoginURL = client.GetLoginUrl(parameters); 

// whenever the browser navigates to a new url, try parsing the url. 
// the url may be the result of OAuth 2.0 authentication. 
FacebookOAuthResult oauthResult; 
if (client.TryParseOAuthCallbackUrl(LoginURL, out oauthResult)) { 
    // The url is the result of OAuth 2.0 authentication 
} else { 
    // The url is NOT the result of OAuth 2.0 authentication. 
} 

現在,當我嘗試爲自己獲取應用程序的訪問令牌時,此工作適用於我。不過,我需要的行爲方式與Graph API Explorer相同。我需要它像Explorer一樣工作的原因是因爲我想在實際的公司頁面下使用Facebook應用程序發佈帖子,所以看起來公司頁面實際上是在發佈Facebook帖子而不是用戶。就像我上面所說的,我可以通過圖形API瀏覽器成功完成此操作,但是在C#中沒有成功完成此操作。

回答

2

才能使用圖形API代表的頁面,你需要得到頁面訪問令牌 - 在這裏看到更多的細節:https://developers.facebook.com/docs/authentication/pages/

  1. 驗證用戶,並要求manage_pages許可
  2. 獲取用戶管理的頁面列表
  3. 解析列表並獲取令牌 - 並將其用於發佈到提要。
+0

確定閱讀你的文章後。我只是意識到我在腦海中想要完成的事情本質上是不可能的。我需要能夠自動化整個過程。但是,我必須先認證用戶並獲取該訪問令牌。除非我將它們重定向到登錄頁面,否則我無法做到這一點。因此,用戶將不得不互動至少登錄到Facebook,然後可以代表用戶發佈帖子。是否有可能延長access_token的時間?這些只持續幾個小時。 – meanbunny 2012-04-13 21:09:35

+1

重新:擴展令牌,看到問題和我的答案在這裏:http://stackoverflow.com/questions/10082531/what-is-the-code-for-getting-a-refreshed-facebook-token-in-an- android-app/10148412#10148412 您將獲得60天有效的新令牌 – avs099 2012-04-13 21:16:41

+0

您真棒!我不得不首先擴展應用程序access_token,然後我可以得到一個特殊的東西,我認爲它會延長訪問令牌以張貼到頁面。慢慢學習,但肯定。 – meanbunny 2012-04-13 21:32:10

相關問題