Here's the code that goes wrong. Access token comes back null, and exception on the last line. /HandleFacebookRegisterMember is the redirect url we send to fb.
[HttpGet]
public ActionResult HandleFacebookRegisterMember()
{
if (Request.QueryString["code"] != null && Request.QueryString["state"] != null)
{
String accessToken = oauth.GetAccessTokenFromAuthCode(Request.QueryString["code"]);
if (accessToken != null)
{
// Initialize a new instance of the FacebookService class so we can make calls to the API
FacebookService service = FacebookService.CreateFromAccessToken(accessToken);
FacebookGetUserOptions options = new FacebookGetUserOptions
{
Identifier = "me",
Fields = new[] { "id", "name", "email", "first_name", "last_name", "gender", "birthday" }
};
FacebookResponse response = service.Users.GetUser(options);
The snippet that you posted doesn't come from this package, so I'm guessing it's something the developer build on top of Skybrud.Social without using the Umbraco package.
Nevertheless, if there is something wrong with the access token, it must be in the GetAccessTokenFromAuthCode method. It doesn't really have any handling if it's receives an error response from the API (I think Facebook's documentation was lacking information on this when I initially made the package).
To debug your issue you could try at replicate what the method does:
The contents variable could have some useful information. If you try this, could you please post the value here? Of course make sure to blank out any sensitive information ;)
Changing FB app ID, but getting null access token
Hi,
I'm having to change to a new FB app, as my company's previous developer seems to have switched the app off and no one else has access to it.
I've updated the app ID and secret key where I can find them, asks me to log in to FB fine, but then I get this error:
"An active access token must be used to query information about the current user"
Debugging shows that oauth.GetAccessTokenFromAuthCode(Request.QueryString["code"]); is reutrning null, and QueryString["code"] is definitely set.
Any ideas why?
Using latest version 1.0.7
Hi Josh,
This package has a dependency for
Skybrud.Social.dll
. Can you confirm that this DLL is version 0.9.6?Older versions of
Skybrud.Social.dll
has some problems as Facebook made some breaking changes to their API.Yeah it's 0.9.6
Here's the code that goes wrong. Access token comes back null, and exception on the last line. /HandleFacebookRegisterMember is the redirect url we send to fb.
Hi again,
The snippet that you posted doesn't come from this package, so I'm guessing it's something the developer build on top of
Skybrud.Social
without using the Umbraco package.Nevertheless, if there is something wrong with the access token, it must be in the
GetAccessTokenFromAuthCode
method. It doesn't really have any handling if it's receives an error response from the API (I think Facebook's documentation was lacking information on this when I initially made the package).To debug your issue you could try at replicate what the method does:
https://github.com/abjerner/Skybrud.Social/blob/v0.9.x/src/Skybrud.Social/Facebook/OAuth/FacebookOAuthClient.cs#L242
The
contents
variable could have some useful information. If you try this, could you please post the value here? Of course make sure to blank out any sensitive information ;)Worked a treat, thanks. It was a domain not listed in app error, I hadn't added localhost :)
Thanks for your help!
is working on a reply...