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