“The domain of this URL isn't included in the app's domains” when it is
I'm trying to post to a Facebook wall from a PHP script. I've created a FB app, installed the Graph PHP API, and implemented some test scripts as follows:
fbinit.php:
<?php
session_start();
require_once('src/Facebook/autoload.php');
$fb = new FacebookFacebook([
'app_id' => 'REDACTED',
'app_secret' => 'REDACTED',
'default_graph_version' => 'v2.9',
]);
?>
fbpost.php:
<?php
include('fbinit.php');
$helper = $fb->getRedirectLoginHelper();
$permissions = ['manage_pages','publish_pages']; //'publish_actions'
$loginUrl = $helper->getLoginUrl('https://www.REDACTED.net/fb-callback.php', $permissions);
echo '<a href="' . htmlspecialchars($loginUrl) . '">Log in with Facebook!</a>';
?>
fb-callback.php:
<?php
include('fbinit.php');
$helper = $fb->getRedirectLoginHelper();
$_SESSION['FBRLH_state']=$_GET['state'];
try {
$accessToken = $helper->getAccessToken();
} catch(FacebookExceptionsFacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (! isset($accessToken)) {
echo 'No OAuth data could be obtained from the signed request. User has not authorized your app yet.';
exit;
}
try {
$response = $fb->get('me/accounts', $accessToken->getValue());
$response = $response->getDecodedBody();
} catch(FacebookExceptionsFacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
echo "<pre>";
print_r($response);
echo "</pre>";
?>
The first time I opened fbpost.php, I was asked to log in to Facebook as expected, and it asked for permission to post on my behalf on the page, which is fine. But then I am redirected to the call back page and presented with the following error:
Graph returned an error: Can't load URL: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and sub-domains of your app to the App Domains field in your app settings.
I have added every combination of the app URL's and callback URL's I can think of, but nothing works. See below for screenshots of the app settings. The App ID and secret are definitely correct.
facebook-graph-api facebook-php-sdk
add a comment |
I'm trying to post to a Facebook wall from a PHP script. I've created a FB app, installed the Graph PHP API, and implemented some test scripts as follows:
fbinit.php:
<?php
session_start();
require_once('src/Facebook/autoload.php');
$fb = new FacebookFacebook([
'app_id' => 'REDACTED',
'app_secret' => 'REDACTED',
'default_graph_version' => 'v2.9',
]);
?>
fbpost.php:
<?php
include('fbinit.php');
$helper = $fb->getRedirectLoginHelper();
$permissions = ['manage_pages','publish_pages']; //'publish_actions'
$loginUrl = $helper->getLoginUrl('https://www.REDACTED.net/fb-callback.php', $permissions);
echo '<a href="' . htmlspecialchars($loginUrl) . '">Log in with Facebook!</a>';
?>
fb-callback.php:
<?php
include('fbinit.php');
$helper = $fb->getRedirectLoginHelper();
$_SESSION['FBRLH_state']=$_GET['state'];
try {
$accessToken = $helper->getAccessToken();
} catch(FacebookExceptionsFacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (! isset($accessToken)) {
echo 'No OAuth data could be obtained from the signed request. User has not authorized your app yet.';
exit;
}
try {
$response = $fb->get('me/accounts', $accessToken->getValue());
$response = $response->getDecodedBody();
} catch(FacebookExceptionsFacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
echo "<pre>";
print_r($response);
echo "</pre>";
?>
The first time I opened fbpost.php, I was asked to log in to Facebook as expected, and it asked for permission to post on my behalf on the page, which is fine. But then I am redirected to the call back page and presented with the following error:
Graph returned an error: Can't load URL: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and sub-domains of your app to the App Domains field in your app settings.
I have added every combination of the app URL's and callback URL's I can think of, but nothing works. See below for screenshots of the app settings. The App ID and secret are definitely correct.
facebook-graph-api facebook-php-sdk
The value of theredirect_uri
parameter needs to be the exact same in your login dialog call, and the subsequent API call that tries to exchange the code for a token. When you have generation of the login URL and handling of the response spread over different scripts (i.e., called via different URLs), that can easily lead to problems like this. Try and explicitly specify the callback URL in yourgetAccessToken
method call as well.
– misorude
Nov 14 '18 at 12:41
Aha, that worked! Specifying the callback URL in getAccessToken() allowed the callback to work and I then got the array representing the pages returned. Thank you! If you post this as an answer I will accept it.
– mashers
Nov 14 '18 at 13:20
add a comment |
I'm trying to post to a Facebook wall from a PHP script. I've created a FB app, installed the Graph PHP API, and implemented some test scripts as follows:
fbinit.php:
<?php
session_start();
require_once('src/Facebook/autoload.php');
$fb = new FacebookFacebook([
'app_id' => 'REDACTED',
'app_secret' => 'REDACTED',
'default_graph_version' => 'v2.9',
]);
?>
fbpost.php:
<?php
include('fbinit.php');
$helper = $fb->getRedirectLoginHelper();
$permissions = ['manage_pages','publish_pages']; //'publish_actions'
$loginUrl = $helper->getLoginUrl('https://www.REDACTED.net/fb-callback.php', $permissions);
echo '<a href="' . htmlspecialchars($loginUrl) . '">Log in with Facebook!</a>';
?>
fb-callback.php:
<?php
include('fbinit.php');
$helper = $fb->getRedirectLoginHelper();
$_SESSION['FBRLH_state']=$_GET['state'];
try {
$accessToken = $helper->getAccessToken();
} catch(FacebookExceptionsFacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (! isset($accessToken)) {
echo 'No OAuth data could be obtained from the signed request. User has not authorized your app yet.';
exit;
}
try {
$response = $fb->get('me/accounts', $accessToken->getValue());
$response = $response->getDecodedBody();
} catch(FacebookExceptionsFacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
echo "<pre>";
print_r($response);
echo "</pre>";
?>
The first time I opened fbpost.php, I was asked to log in to Facebook as expected, and it asked for permission to post on my behalf on the page, which is fine. But then I am redirected to the call back page and presented with the following error:
Graph returned an error: Can't load URL: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and sub-domains of your app to the App Domains field in your app settings.
I have added every combination of the app URL's and callback URL's I can think of, but nothing works. See below for screenshots of the app settings. The App ID and secret are definitely correct.
facebook-graph-api facebook-php-sdk
I'm trying to post to a Facebook wall from a PHP script. I've created a FB app, installed the Graph PHP API, and implemented some test scripts as follows:
fbinit.php:
<?php
session_start();
require_once('src/Facebook/autoload.php');
$fb = new FacebookFacebook([
'app_id' => 'REDACTED',
'app_secret' => 'REDACTED',
'default_graph_version' => 'v2.9',
]);
?>
fbpost.php:
<?php
include('fbinit.php');
$helper = $fb->getRedirectLoginHelper();
$permissions = ['manage_pages','publish_pages']; //'publish_actions'
$loginUrl = $helper->getLoginUrl('https://www.REDACTED.net/fb-callback.php', $permissions);
echo '<a href="' . htmlspecialchars($loginUrl) . '">Log in with Facebook!</a>';
?>
fb-callback.php:
<?php
include('fbinit.php');
$helper = $fb->getRedirectLoginHelper();
$_SESSION['FBRLH_state']=$_GET['state'];
try {
$accessToken = $helper->getAccessToken();
} catch(FacebookExceptionsFacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (! isset($accessToken)) {
echo 'No OAuth data could be obtained from the signed request. User has not authorized your app yet.';
exit;
}
try {
$response = $fb->get('me/accounts', $accessToken->getValue());
$response = $response->getDecodedBody();
} catch(FacebookExceptionsFacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
echo "<pre>";
print_r($response);
echo "</pre>";
?>
The first time I opened fbpost.php, I was asked to log in to Facebook as expected, and it asked for permission to post on my behalf on the page, which is fine. But then I am redirected to the call back page and presented with the following error:
Graph returned an error: Can't load URL: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and sub-domains of your app to the App Domains field in your app settings.
I have added every combination of the app URL's and callback URL's I can think of, but nothing works. See below for screenshots of the app settings. The App ID and secret are definitely correct.
facebook-graph-api facebook-php-sdk
facebook-graph-api facebook-php-sdk
asked Nov 14 '18 at 12:32
mashersmashers
443315
443315
The value of theredirect_uri
parameter needs to be the exact same in your login dialog call, and the subsequent API call that tries to exchange the code for a token. When you have generation of the login URL and handling of the response spread over different scripts (i.e., called via different URLs), that can easily lead to problems like this. Try and explicitly specify the callback URL in yourgetAccessToken
method call as well.
– misorude
Nov 14 '18 at 12:41
Aha, that worked! Specifying the callback URL in getAccessToken() allowed the callback to work and I then got the array representing the pages returned. Thank you! If you post this as an answer I will accept it.
– mashers
Nov 14 '18 at 13:20
add a comment |
The value of theredirect_uri
parameter needs to be the exact same in your login dialog call, and the subsequent API call that tries to exchange the code for a token. When you have generation of the login URL and handling of the response spread over different scripts (i.e., called via different URLs), that can easily lead to problems like this. Try and explicitly specify the callback URL in yourgetAccessToken
method call as well.
– misorude
Nov 14 '18 at 12:41
Aha, that worked! Specifying the callback URL in getAccessToken() allowed the callback to work and I then got the array representing the pages returned. Thank you! If you post this as an answer I will accept it.
– mashers
Nov 14 '18 at 13:20
The value of the
redirect_uri
parameter needs to be the exact same in your login dialog call, and the subsequent API call that tries to exchange the code for a token. When you have generation of the login URL and handling of the response spread over different scripts (i.e., called via different URLs), that can easily lead to problems like this. Try and explicitly specify the callback URL in your getAccessToken
method call as well.– misorude
Nov 14 '18 at 12:41
The value of the
redirect_uri
parameter needs to be the exact same in your login dialog call, and the subsequent API call that tries to exchange the code for a token. When you have generation of the login URL and handling of the response spread over different scripts (i.e., called via different URLs), that can easily lead to problems like this. Try and explicitly specify the callback URL in your getAccessToken
method call as well.– misorude
Nov 14 '18 at 12:41
Aha, that worked! Specifying the callback URL in getAccessToken() allowed the callback to work and I then got the array representing the pages returned. Thank you! If you post this as an answer I will accept it.
– mashers
Nov 14 '18 at 13:20
Aha, that worked! Specifying the callback URL in getAccessToken() allowed the callback to work and I then got the array representing the pages returned. Thank you! If you post this as an answer I will accept it.
– mashers
Nov 14 '18 at 13:20
add a comment |
1 Answer
1
active
oldest
votes
The value of the redirect_uri
parameter needs to be the exact same in your login dialog call, and the subsequent API call that tries to exchange the code for a token.
When you have generation of the login URL and handling of the response spread over different scripts (i.e., called via different URLs), that can easily lead to problems like this. The SDK tries to figure out the value based on the current script URL, if left to its own devices.
In such a case, explicitly specify the callback URL in your getAccessToken
method call as well.
Specifying the callback URL in getAccessToken() allowed the callback to work and I then got the array representing the pages returned. Thank you!
– mashers
Nov 14 '18 at 13:26
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300350%2fthe-domain-of-this-url-isnt-included-in-the-apps-domains-when-it-is%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The value of the redirect_uri
parameter needs to be the exact same in your login dialog call, and the subsequent API call that tries to exchange the code for a token.
When you have generation of the login URL and handling of the response spread over different scripts (i.e., called via different URLs), that can easily lead to problems like this. The SDK tries to figure out the value based on the current script URL, if left to its own devices.
In such a case, explicitly specify the callback URL in your getAccessToken
method call as well.
Specifying the callback URL in getAccessToken() allowed the callback to work and I then got the array representing the pages returned. Thank you!
– mashers
Nov 14 '18 at 13:26
add a comment |
The value of the redirect_uri
parameter needs to be the exact same in your login dialog call, and the subsequent API call that tries to exchange the code for a token.
When you have generation of the login URL and handling of the response spread over different scripts (i.e., called via different URLs), that can easily lead to problems like this. The SDK tries to figure out the value based on the current script URL, if left to its own devices.
In such a case, explicitly specify the callback URL in your getAccessToken
method call as well.
Specifying the callback URL in getAccessToken() allowed the callback to work and I then got the array representing the pages returned. Thank you!
– mashers
Nov 14 '18 at 13:26
add a comment |
The value of the redirect_uri
parameter needs to be the exact same in your login dialog call, and the subsequent API call that tries to exchange the code for a token.
When you have generation of the login URL and handling of the response spread over different scripts (i.e., called via different URLs), that can easily lead to problems like this. The SDK tries to figure out the value based on the current script URL, if left to its own devices.
In such a case, explicitly specify the callback URL in your getAccessToken
method call as well.
The value of the redirect_uri
parameter needs to be the exact same in your login dialog call, and the subsequent API call that tries to exchange the code for a token.
When you have generation of the login URL and handling of the response spread over different scripts (i.e., called via different URLs), that can easily lead to problems like this. The SDK tries to figure out the value based on the current script URL, if left to its own devices.
In such a case, explicitly specify the callback URL in your getAccessToken
method call as well.
answered Nov 14 '18 at 13:25
misorudemisorude
1,8672312
1,8672312
Specifying the callback URL in getAccessToken() allowed the callback to work and I then got the array representing the pages returned. Thank you!
– mashers
Nov 14 '18 at 13:26
add a comment |
Specifying the callback URL in getAccessToken() allowed the callback to work and I then got the array representing the pages returned. Thank you!
– mashers
Nov 14 '18 at 13:26
Specifying the callback URL in getAccessToken() allowed the callback to work and I then got the array representing the pages returned. Thank you!
– mashers
Nov 14 '18 at 13:26
Specifying the callback URL in getAccessToken() allowed the callback to work and I then got the array representing the pages returned. Thank you!
– mashers
Nov 14 '18 at 13:26
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300350%2fthe-domain-of-this-url-isnt-included-in-the-apps-domains-when-it-is%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The value of the
redirect_uri
parameter needs to be the exact same in your login dialog call, and the subsequent API call that tries to exchange the code for a token. When you have generation of the login URL and handling of the response spread over different scripts (i.e., called via different URLs), that can easily lead to problems like this. Try and explicitly specify the callback URL in yourgetAccessToken
method call as well.– misorude
Nov 14 '18 at 12:41
Aha, that worked! Specifying the callback URL in getAccessToken() allowed the callback to work and I then got the array representing the pages returned. Thank you! If you post this as an answer I will accept it.
– mashers
Nov 14 '18 at 13:20