1
我已經通過至少100百個訪問令牌問題進行了搜索,但沒有找到解決我的問題的方法。我正在使用Facebook的sdk進行身份驗證,但是當我嘗試簡單。獲取「我」時,出現此錯誤的錯誤:「(OAuthException)必須使用活動訪問令牌來查詢有關當前用戶的信息。」我使用.NET 3.5框架,所以我不能使用'動態'。當我用一個有效的ID代替「我」時它的作用並顯示名稱。當我嘗試發佈feed時,出現「(OAuthException)(#200)用戶尚未授權應用程序執行此操作。」 任何幫助將是偉大的。 謝謝。使用Facebook獲取c#webforms的訪問令牌時出錯c#sdk
這裏是我的代碼:
var webRequest = (HttpWebRequest)HttpWebRequest.Create("https://graph.facebook.com/oauth/access_token");
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
var requestString = "client_id=[appid]&client_secret=[secret]&redirect_uri=http%3A%2F%2Fwww.website.com&grant_type=client_credentials&scope=publish_stream,read_stream,offline_access";
byte[] bytedata = Encoding.UTF8.GetBytes(requestString);
webRequest.ContentLength = bytedata.Length;
var requestStream = webRequest.GetRequestStream();
requestStream.Write(bytedata, 0, bytedata.Length);
requestStream.Close();
var response = webRequest.GetResponse();
var responseStream = new StreamReader(response.GetResponseStream());
var responseString = responseStream.ReadToEnd();
responseStream.Close();
response.Close();
if (!String.IsNullOrEmpty(responseString))
{
var accessToken = responseString.Replace("access_token=", "");
var fb = new FacebookWebClient(accessToken.ToString());
var me = fb.Get<FBUser>("100000219214008");
string firstName = me.name;
var postparameters = new Dictionary<string, object>();
postparameters["message"] = "Hello world!";
postparameters["name"] = "This is a name";
postparameters["link"] = "http://thisisalink.com";
postparameters["description"] = "This is a description";
var result = fb.Post("/100000219214008/feed", postparameters);
Response.Write (firstName.ToString());
}
關於facebook的WEBFORM問題,似乎沒有多少人以這種方式使用它。這種方法的文檔方式幾乎沒有。所有示例都關注Winforms或MVC。 MVC是如此臃腫,我不明白爲什麼有人會想要使用它,除非他們喜歡MVC工作的複雜方式。我工作的一家廣告公司花費了750,000美元在一個項目上,花了6個月時間與一個由10位開發人員組成的團隊[外包],該項目就像80美元!我在30分鐘內使用簡單的網絡表單和模板重新編寫了網站 - 總計350千字節的項目。 –
無論如何..它似乎需要從Facebook的SDK的C#關於Web窗體的支持,因爲我無法想象任何人使用MVC的一頁。思考? –