0
我使用的SDK SDK版本爲6.0.10.0的Facebook.dll。我們正在測試我們的應用程序,我的一個用戶無法登錄。用戶使用Chrome瀏覽器在iMac上。需要幫助找出錯誤「代碼無效或已過期」
我正在使用服務器端流程,根本不使用Facebook Javascript SDK。
下面是服務器端的代碼片段我用來檢索從Facebook的數據... ...(此代碼直接從樣品來的地方,所以信用是由於筆者:-))
var fbClient = new FacebookClient();
var oauthResult = fbClient.ParseOAuthCallbackUrl(pRequestUri);
string accessToken = null;
DateTime expires = DateTime.Now;
// Exchange the code for an access token
dynamic result = fbClient.Get("/oauth/access_token", new
{
client_id = ConfigurationManager.AppSettings["FacebookAppId"],
redirect_uri = pRedirectUri.AbsoluteUri,
client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"],
code = oauthResult.Code,
});
accessToken = result.access_token;
expires = DateTime.UtcNow.AddSeconds(Convert.ToDouble(result.expires));
// Get the user's profile information
dynamic me = fbClient.Get("/me",
new
{
fields = "first_name,last_name,email,name",
access_token = accessToken
});
// Read the Facebook user values
string sfacebookId = me.id;
string firstName = me.first_name;
string lastName = me.last_name;
string email = me.email;
以下是我的日誌中的例外情況的詳細信息。
(OAuthException - #100) Code was invalid or expired.
This may be because the user logged out or may be due to a system error.
source="Facebook" detail="Facebook.FacebookOAuthException: (OAuthException - #100) Code was invalid or expired. This may be because the user logged out or may be due to a system error.
Stack Trace:
at Facebook.FacebookClient.ProcessResponse(HttpHelper httpHelper, String responseString, Type resultType, Boolean containsEtag, IList`1 batchEtags)
at Facebook.FacebookClient.Api(HttpMethod httpMethod, String path, Object parameters, Type resultType)
at Facebook.FacebookClient.Get(String path, Object parameters)
從Facebook返回的查詢字符串包含參數代碼,並且它有一個值。
從堆棧跟蹤中很容易看出,代碼中的第一個.Get()方法調用最終調用引發錯誤的.ProcessResponse()方法。
不幸的是,我到處搜索關於如何處理過期的訪問令牌的問題。
就我而言,我還沒有檢索到訪問令牌,它是我的代碼已過期或無效。我如何申請一個新的代碼?
感謝,
嘗試使用TryParseOAuthCallbackUrl並檢查result.IsSuccess是否爲true並且!string.IsNullOrEmpty(result.Code) – prabir 2012-07-27 18:06:55
@prabir:添加這些檢查將確保代碼有效,但我仍然希望用戶access_token。如何在這種情況下獲取他們的access_token?你告訴我什麼會阻止用戶登錄。 – RDotLee 2012-07-27 18:09:43
你確定在querystring中有代碼嗎? – prabir 2012-07-27 18:33:17