Reputation: 3929
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?
Upvotes: 1
Views: 4459
Reputation: 1
https://www.facebook.com/dialog/oauth?client_id=[Your API KEY]&redirect_url=[Service that will handle Authentication]&scope=[Permissions you Need].
Upvotes: 0
Reputation: 20753
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"]);
}
This signed_request contains whole damn required information (including access token).
Upvotes: 0
Reputation: 1554
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/
Upvotes: 1