1

I try to get access token on Facebook API.

According to this answer I need first to build a link https://www.facebook.com/dialog/oauth?client_id=[Your API KEY]&redirect_url=[Service that will handle Authentication]&scope=[Permissions you Need]. In my case it looks like this:

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

After this it should redirect to specified url with a query string containing code, which in turn can be used to get access token of a user. But in my case it redirects to the following page: http://www.facebook.com/connect/blank.html#_=_ without any queries.

Why is that? How I can get code of a user?

Community
  • 1
  • 1
Sergey Ivanov
  • 3,719
  • 7
  • 34
  • 59

3 Answers3

1

your redirect_uri shouldn't be http://www.facebook.com/connect/login_success.html it should be a url from your application that would handle facebook authentication

update

if you are still developing your website and you want to test it on your local host you could use localhost/mydevwebsite/login_success/ otherwise use the domain for the application you are working on myappdomain.com/loginsuccess/

amdorra
  • 1,536
  • 9
  • 18
0
  1. Access the signed_request parameter and prompt the user to authorize your app:

    $app_id = "YOUR_APP_ID";
    
    $canvas_page = "YOUR_CANVAS_PAGE_URL";
    
    $auth_url = "https://www.facebook.com/dialog/oauth?client_id=" 
        . $app_id . "&redirect_uri=" . urlencode($canvas_page);
    
    $signed_request = $_REQUEST["signed_request"];
    
    list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
    
    $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
    
    if (empty($data["user_id"])) {
        echo("<script> top.location.href='" . $auth_url . "'</script>");
    } else {
        echo ("Welcome User: " . $data["user_id"]);
    } 
    
  2. This signed_request contains whole damn required information (including access token).

Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
  • I have no experience working in PHP. Can you translate it to Python? – Sergey Ivanov Aug 25 '13 at 21:25
  • And I've no exp with python, but Ill explain you the concept. `$signed_request = $_REQUEST["signed_request"];` step triies to fetch the variable singed_request from the url; if it is found, you can save the access token and perform functions, else it will redirect user to auth_url for the authorization step and the process is repeated. – Sahil Mittal Aug 25 '13 at 21:37
  • 1
    This might be useful: http://stackoverflow.com/questions/464040/how-are-post-and-get-variables-handled-in-python. But I'm not sure – Sahil Mittal Aug 25 '13 at 21:39
0

https://www.facebook.com/dialog/oauth?client_id=[Your API KEY]&redirect_url=[Service that will handle Authentication]&scope=[Permissions you Need].

  • Welcome to Stack Overflow! While this may help answer the question, [it would be preferable](http://meta.stackoverflow.com/q/8259) to include more of an explanation. – Nathan Tuggy Dec 12 '14 at 08:32