I’m using version 6.0.10.0 of the Facebook.dll from the SDK. We are beta testing our application and one of my users cannot login. The user is on an iMac using Chrome.
I am using the server side flow, not using the Facebook Javascript SDK at all.
Here is a snippet of server side code i’m using to retrieve data from Facebook… (This code came directly from a sample somewhere, so credit is due to that author 🙂 )
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;
Here is the detail of the exception from my logs.
(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)
The query string returned from Facebook includes the parameter code and it has a value.
It is easy to see from the stack trace that the first .Get() method call in my code ends up calling the .ProcessResponse() method which throws the error.
Unfortunately, everywhere I search talks about what to do with an expired access token.
In my case, I have not even retrieved an access token yet, it is my code that is expired or invalid. How can I request a new code?
Thanks,
I could never get the server side flow working for all my users, so I went ahead and switched to the FB Javascript SDK and it is working for me now.