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 6944981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:22:38+00:00 2026-05-27T13:22:38+00:00

I’m starting to use facebook Graph API and I’m going to retrieve an access

  • 0

I’m starting to use facebook Graph API and I’m going to retrieve an access token with some simple HTTP requests via java.

Following https://developers.facebook.com/docs/authentication/
I created a new app but I don’t have a domain so
I make an HTTP request to

http://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&
redirect_uri=https://www.facebook.com/connect/login_success.html

for a server-side flow, and I suppose to get redirect to a success page with a code in the URL. Then I would use this code make another HTTP request to

graph.facebook.com/oauth/access_token?
client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&
client_secret=YOUR_APP_SECRET&code=THE_CODE_FROM_ABOVE

and finally get my access token.

I used both java.net.HttpURLConnection and org.apache.http.HttpResponse,
but, in both cases, executing the first call I get as response the HTML of a Facebook login page.

If I use this HTML to create a webpage and then I simply click on the Login button (without inserting username and password) I get the success page with the code!

In the HTML the field submit of the button Login is empty and I can’t retrieve redirect URLs… I can just read an alternate link in the <meta> tag which generate an auth_token (what is it? It is very different wrt an normal access_token…).

So what I ask is:

  1. it is possible to detect the hidden redirect in some way just
    using java.net.HttpURLConnection or
    org.apache.http.HttpResponse?

  2. if yes, how is the mechanism? Is it related to the auth_token?

  3. if no, is it possible with other libraries? (I used also restfb,
    but they seems to require an access token inserted “by hand” as an
    arg, and I also saw facebook-java-api but it seems old).


Also if I’m logged in Facebook, executing the first HTTP call via Java I get as response the HTML of a Facebook login page.

Using HTML to create a webpage and then I simply click on the Login button (without inserting username and password) I get the success.htm page with the code parameter in the URL.

If I use the original URL directly in my browser I can directly obtain the success.htm page without passages in the middle.

So I suppose the problem is in the management of cookies: in Java (executed in Eclipse) I cannot access my browser’s cookies.

I tried to redirect to use a Servlet but I get the error about the domain:
ServletURL is not a Facebook domain or a “site URL” registered for my app (actually I did’t set a site URL for my app… and that’s the problem core).

In any case here
http://developers.facebook.com/docs/authentication/
in the section App types > Desktop apps they say:

[…] After the user authorizes your app [I allowed everything], we
redirect the user back to the redirect_uri with the access token in
the URI fragment: […]

Detect this redirect and then read the access token out of the URI
using whatever mechanisms provided by your framework of choice. […]

So I think that it is still possible to detect this redirect via Java. How?

  • 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-05-27T13:22:38+00:00Added an answer on May 27, 2026 at 1:22 pm

    If you do not have a domain yet I recommend you using localhost as a domain. That way you can test it on your local web server / local app.

    Using HttpURLConnection works fine.
    This is how we do it.

    Redirect to: 
    "https://graph.facebook.com/oauth/authorize?" +
                "client_id=" + clientId + "&" +
                "redirect_uri=" + URLEncoder.encode(returnUrl, "utf-8") 
    // After redirect to the return url do the following:
    
    //Make a http request to 
    "https://graph.facebook.com/oauth/access_token?client_id=" +
                "client_id=" + clientId + "&" +
                "redirect_uri=" + URLEncoder.encode(returnUrl, "utf-8")  + "&"+
                "client_secret=" + clientSecret + "&"+
                "code=" + request.getParameter("code");
    

    This will return an access token which you can query facebook with

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am writing an app with both english and french support. The app requests

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.