Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Josh Irish 4 posts 84 karma points
    May 30, 2019 @ 18:04
    Josh Irish
    0

    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

  • Anders Bjerner 487 posts 2995 karma points MVP 8x admin c-trib
    May 31, 2019 @ 06:47
    Anders Bjerner
    0

    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.

  • Josh Irish 4 posts 84 karma points
    May 31, 2019 @ 15:49
    Josh Irish
    0

    Yeah it's 0.9.6

  • Josh Irish 4 posts 84 karma points
    May 31, 2019 @ 17:05
    Josh Irish
    0

    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);
    
  • Anders Bjerner 487 posts 2995 karma points MVP 8x admin c-trib
    May 31, 2019 @ 21:51
    Anders Bjerner
    100

    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 ;)

  • Josh Irish 4 posts 84 karma points
    May 31, 2019 @ 22:23
    Josh Irish
    0

    Worked a treat, thanks. It was a domain not listed in app error, I hadn't added localhost :)

    Thanks for your help!

Please Sign in or register to post replies

Write your reply to:

Draft