讓我知道其實你有什麼requirement.I認爲你的第一個要求是添加Facebook登錄(或Facebook頁面註冊)按鈕在您的網站登錄頁面。
step1:您需要在Facebook上註冊一個新的facebook應用程序。 步驟2:安裝facebook c#sdk。您可以手動下載zip文件或使用nuget安裝它。我推薦第二個選項。我正在使用c#sdk 5.4.1 What is nuget? How to install a package using nuget? 第3步:現在您可以添加名稱空間facebook步驟4:在登錄頁面(例如login.aspx)插入一個登錄按鈕(簡單地說就是一個帶有文本登錄按鈕)。讓它成爲按鈕1 第5步:點擊按鈕重定向到另一頁面(讓login1.aspx) 這裏是使用Facebook登錄1
的樣本代碼; //
FacebookOAuthClient fb = new FacebookOAuthClient();
UriBuilder red = new UriBuilder("www.example.com/Login1.aspx");
protected void Page_Load(object sender, EventArgs e)
{
string appid = "{your app id}";
string appsecret = "{your app secret}";
string permissions = "publish_stream";
if(Request.QueryString["code"] == null)
{
try
{
Response.Redirect("https://www.facebook.com/dialog/oauth?client_id=" + appid + "&redirect_uri=" + red.Uri.ToString() + "&scope=" + permissions +"&state=djfjfdjj");
}
catch (Exception b)
{
Label1.Text = b.ToString();
}
}
else
{
try
{
FacebookOAuthClient cl = new FacebookOAuthClient();
cl.RedirectUri = red.Uri;
cl.AppId = appid;
cl.AppSecret = appsecret;
dynamic result = cl.ExchangeCodeForAccessToken(Request.QueryString["code"]);
Label1.Text = Convert.ToString(result);
if (result["access_token"] != null)
{
Session["access_token"] = result["access_token"].ToString();//Now you have access token
Response.Redirect("Welcome.aspx");//replace welcome.aspx
}
else
{
Label1.Text = "Unable to authenticate\n Please try again later";
}
}
catch(Exception b)
{
Label1.Text = b.ToString();
}
}
}
現在你有一個訪問保存在會話中的令牌。
用於獲取客戶的基本信息
dynamic me=fb.Get("\me");
它cludes姓,名,電子郵件地址,位置,當前的圖像URL等user.Now您可以使用此電子郵件或名稱來驗證您的用戶或註冊新用戶等(由您決定)。
在該網頁上公佈是可能的,但diffiult How can I use the Facebook C# SDK to post on Facebook Pages
爲什麼appid?我的應用程序不是Facebook應用程序,它是基於WPF的桌面應用程序 – 2012-07-06 22:33:20