0
我使用Facebook API w/oAuth使用其Javascript SDK登錄並設置oAuth = true。我可以從SDK登錄成功,並讓我的xfbml正確呈現。'Facebook.FacebookApplication'的類型初始值設定項引發異常
我正在使用Facebook C#sdk檢索用戶標識併發布到FB。我寫了一個小測試頁來做到這一點。
HTML是:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="fbtest.aspx.cs" Inherits="fbtest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
ID:<asp:label runat="server" text="Label" ID="Userid"></asp:label><div />
<asp:label runat="server" text="Label" ID="FacebookTokenLabel"></asp:label>
</div>
</form>
</body>
</html>
後面的代碼是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Facebook;
using Facebook.Web;
public partial class fbtest : System.Web.UI.Page
{
private FacebookWebClient _facebookApp;
protected void Page_Load(object sender, EventArgs e)
{
try
{
// FacebookWebContext fbWebContext = FacebookWebContext.Current;
// FacebookTokenLabel.Text += fbWebContext.AccessToken;
FacebookWebClient fb = new FacebookWebClient();
dynamic me = fb.Get("me");
FacebookTokenLabel.Text = me.name;
Userid.Text = me.id;
}
catch (Exception ex)
{
FacebookTokenLabel.Text = ex.Message + ":" + ex.StackTrace;
}
}
}
我嘗試了所有的瀏覽器(IE9,Chrome瀏覽器14.0.835.186 m和FF 6.0.2),我會得到相同的例外:
ID:Label
The type initializer for 'Facebook.FacebookApplication' threw an exception.:
at Facebook.FacebookApplication.get_Current() in e:\Prabir\Documents\Projects\facebooksdk\v5.2.1\Source\Facebook\FacebookApplication.cs:line 48
at Facebook.Web.FacebookWebContext..ctor() in e:\Prabir\Documents\Projects\facebooksdk\v5.2.1\Source\Facebook.Web\FacebookWebContext.cs:line 48
at Facebook.Web.FacebookWebContext.get_Current() in e:\Prabir\Documents\Projects\facebooksdk\v5.2.1\Source\Facebook.Web\FacebookWebContext.cs:line 96
at fbtest.Page_Load(Object sender, EventArgs e) in c:\inetpub\vhosts\beirutna.com\subdomains\beta\httpdocs\fbtest.aspx.cs:line 16
你可以嘗試自己: http://beta.beirutna.com並登錄頂部對,它會顯示你的用戶名和磁貼。然後去:http://http://beta.beirutna.com/fbtest.aspx