(OAuthException - #2500) An active access token must be used to query information about the current user

12,282

you are getting access token for the APPLICATION, not for a user. Therefore, "me" does not make sense. You should supply ID there - either your user ID, or your app ID, or any other ID your app has permissions for.

both calls worked for with your example:

dynamic me = client.Get("1000<<MY_USER_ID>>5735");

dynamic theApp = client.Get("201193246663533");
Share:
12,282
DarthVader
Author by

DarthVader

Updated on August 21, 2022

Comments

  • DarthVader
    DarthVader over 1 year
            string accessToken = GetAccessToken();
            string accessKey = accessToken.Split('=')[1];
    
            var client = new FacebookClient(accessKey);
            dynamic me = client.Get("me");
    

    here is the method to get access token and it does return a valid access token

    private static string GetAccessToken()
        {
            // Create a request using a URL that can receive a post. 
            WebRequest request = WebRequest.Create("https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=201193246663533&client_secret=secretkeyhere");
            // Set the Method property of the request to POST.
            request.Method = "POST";
            // Create POST data and convert it to a byte array.
            string postData = "This is a test that posts this string to a Web server.";
            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            // Set the ContentType property of the WebRequest.
            request.ContentType = "application/x-www-form-urlencoded";
            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;
            // Get the request stream.
            Stream dataStream = request.GetRequestStream();
            // Write the data to the request stream.
            dataStream.Write(byteArray, 0, byteArray.Length);
            // Close the Stream object.
            dataStream.Close();
            // Get the response.
            WebResponse response = request.GetResponse();
            // Display the status.
            Console.WriteLine(((HttpWebResponse)response).StatusDescription);
            // Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd();
            // Display the content.
            Console.WriteLine(responseFromServer);
            // Clean up the streams.
            reader.Close();
            dataStream.Close();
            response.Close();
    
            return responseFromServer;
        }
    

    However, when I debug over

    dynamic me = client.Get("me");
    

    throws this exception:

    (OAuthException - #2500) An active access token must be used to query information about the current user.

    How can i fix this?

  • DarthVader
    DarthVader about 12 years
    thanks for the answer but how do i get the user per request. I m not interested in my info, i want the users info. therefore if u look at:csharpsdk.org/docs/web/getting-started.html , it says i need to use "me"
  • avs099
    avs099 about 12 years
    i think you are confused. You cannot get access token for the user without displaying FB authentication dialog. What you are getting with your code is APPLICATION token - which you can use, for example, to get Insight data, or create test users, and so on. If you want to authenticate a USER - then you should use either server-side flow, or Javascript SDK.
  • avs099
    avs099 about 12 years
    check this out: stackoverflow.com/questions/8625708/… - that can help you to understand server-side flow for authentication. And here is the official page for server-side authentication: developers.facebook.com/docs/authentication/server-side
  • Heemanshu Bhalla
    Heemanshu Bhalla over 7 years
    @avs099 can we get friends info and post without using dialog . if follow server-side flow link you provided but that's looks old now you can check my comments there