Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8426877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:38:53+00:00 2026-06-10T04:38:53+00:00

The main question: How am I supposed to extend the 2 hour access token

  • 0

The main question: How am I supposed to extend the 2 hour access token for the 60 day access token via the C# SDK? Can you provide a sample of just that section where the code has already been traded for the 2 hour access token?

Background: I’ve been looking around on here and trying various solutions and haven’t found one that works for me yet. I can successfully make the /me call and get the information about the current user however when I try to extend the access token it fails.

The goal of this app is to allow a user to set up a post and to monitor likes and comments after the fact for a set period of time. We need the 60 day token for this, obviously.

I am taking this project over after someone else did 90% of the work when you could request the permanent token. It’s my job to fix it so that we can use the 60 day token. I may ask very stupid follow up questions. Be prepared!

The current flow: The user sets up his post, clicks a button, we prompt them to auth our app/log into facebook via the javascript sdk. After they log in we process other unrelated things in javascript and then AJAX it over to C# to save some information to our database (including the token) and make the post. Everything goes great, I get the access token just fine in javascript and I can use that 2 hour token to get info on the user who’s logged in however when I try to extend I get one of two errors which I’ll mention below with the code that causes them.

What I’ve tried:

Working:
I believe I found this in another post here.
var fbClient = new FacebookClient(accessToken);

            Dictionary<string, object> parameters = new Dictionary<string, object>();
            parameters.Add("client_id", appId);
            parameters.Add("redirect_uri", redirectURI);
            parameters.Add("client_secret", appSecret);
            parameters.Add("code", accessToken);

            var result = fbClient.Get("/me", parameters);

Not working:
This came from various places including here and the sdk docs. I’ve seen people including the redirect url and saying it needs to match the one when you originally got the accesstoken but we did that in javascript and didn’t use a redirect url.
Dictionary parameters2 = new Dictionary();

            parameters2.Add("client_id", appId);
            //parameters2.Add("redirect_uri", redirectURI);
            parameters2.Add("client_secret", appSecret);
            //parameters2.Add("code", accessToken);
            parameters2.Add("grant_type", "fb_exchange_token");
            parameters2.Add("fb_exchange_token", accessToken);

            var result2 = fbClient.Get("/oauth/access_token", parameters2);

Error: {Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: a. Line 1, position 1.
Error2: If I comment out grant_type and fb_exchange_token and uncomment code and the redirecturi I get the same error as the next method…

Not working:
This I grabbed from another post here copy/paste rename to match my vars.
Unable to get long lived expiration token

            dynamic result3 = new ExpandoObject();
            try
            {
                dynamic parameters3 = new ExpandoObject();
                parameters3.grant_type = "fb_exchange_token";
                parameters3.fb_exchange_token = accessToken;
                parameters3.client_id = appId;
                parameters3.client_secret = appSecret;
                result3 = fbClient.Get("oauth/access_token", parameters);
            }
            catch (FacebookOAuthException err)
            {
                result3.error = "Error";
                result3.message = err.Message;
            }
            catch (Exception err)
            {
                result3.error = "Error";
                result3.message = err.Message;
            }

Error: {(OAuthException) (OAuthException) Invalid verification code format.}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:38:54+00:00Added an answer on June 10, 2026 at 4:38 am

    Use the following code with Facebook.NET and Json.NET in a handler file that is your callback.

    public void ProcessRequest (HttpContext context)
        {
            if (context.Request.Params.Get("error_reason") == "user_denied")
            {
                context.Response.Write("Access Denied");
            }
            else if (context.Request.Params.Get("code") != null && context.Request.Params.Get("code") != "")
            {
                string shorttoken = HttpUtility.ParseQueryString(HttpUtil.GetHtmlPage("https://graph.facebook.com/oauth/access_token?client_id=" + APP_ID + "&redirect_uri=http://huadianz.me/mvp/auth/FacebookOAuth.ashx&client_secret=" + APP_SECRET + "&code=" + context.Request.Params.Get("code")))["access_token"];
                string longtoken = HttpUtility.ParseQueryString(HttpUtil.GetHtmlPage("https://graph.facebook.com/oauth/access_token?client_id=" + APP_ID + "&client_secret=" + APP_SECRET + "&grant_type=fb_exchange_token&fb_exchange_token=" + shorttoken))["access_token"];
    
                Facebook.FacebookClient fc = new Facebook.FacebookClient(longtoken);
                dynamic result = fc.Get("me");
    
                context.Response.Redirect("/");
                //Store Token here
            }
        }
    

    My Utilities file is here:

    public static class HttpUtil
    {
        public static string GetHtmlPage(string strURL)
        {
            String strResult;
            WebResponse objResponse;
            WebRequest objRequest = HttpWebRequest.Create(strURL);
            objResponse = objRequest.GetResponse();
            using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
            {
                strResult = sr.ReadToEnd();
                sr.Close();
            }
            return strResult;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My main question is given a feature centroid, how can I draw it in
TL;DR: The question is: Do you know of a cross-platform library that I can
Main question is what are the implications of allowing the this keyword to be
My main question is : Is there a good practice to serve binary files
I guess my main question is, will this always work as long as I
The title is the main question. The exact scenario (I am 'using namespace std;'):
This was the main question posed by Greg Wilson's bits of evidence presentation. I'm
Here's the main question I guess : Is there a .NET way to get
first of all, my main question: What are some good troubleshooting techniques when you
TLDR; skip to the bottom paragraph for the main question. I'll try to keep

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.