2011-11-22 78 views
1

我在我的網站上使用Facebook C#SDK,並試圖訪問Facebook所做的cookie,當用戶選擇使用Facebook作爲登錄時,但我我收到以下錯誤:試圖從代碼隱藏獲取Facebook Cookie,但越來越(OAuthException)

(OAuthException) An active access token must be used to query information about the current user.

這裏是我使用的代碼:

var client = new FacebookClient([App ID], [App Secret]); 
dynamic me = client.Get("me"); 
string firstName = me.first_name; 

Response.Write(firstName); 

我到底做錯了什麼?

在此先感謝

回答

0

你需要嘗試訪問用戶之前,先授權。這是必要的重定向和管道讓Facebook設置cookie。

var auth = new CanvasAuthorizer { Permissions = new string[] {"user_about_me"} }; 
if (auth.Authorize()) { 
    var client = new FacebookClient([App ID], [App Secret]); 
    dynamic me = client.Get("me"); 
    string firstName = me.first_name; 
    Response.Write(firstName); 
}