Facebook网址被拒绝

时间:2016-04-12 14:43:08

标签: facebook facebook-graph-api

我正在编写一个自动发布到我的Facebook墙上的PHP脚本。

但是我收到了这个错误:

  

应用程序配置不允许使用URL:一个或多个   应用程序的设置不允许使用给定的URL。它必须匹配   网站URL或Canvas URL,或域必须是子域   App的一个域名。

不确定我是否正确行事,但我添加了我的网络域名,可以将其称为http://123.1.2.3到开发者页面下的应用程序网站。

我在php上将此http://123.1.2.3/folder/subfolder/index.php称为属于声明的域名。为什么我拒绝访问?

require_once __DIR__ . '/src/Facebook/autoload.php';

$fb = new Facebook\Facebook([
  'app_id' => '[MY_APP_ID]',
  'app_secret' => '[MY_APP_SECRET]',
  'default_graph_version' => 'v2.5',
]);



$helper = $fb->getRedirectLoginHelper();
$permissions = ['email', 'publish_actions','publish_pages']; // optional
try {
    if (isset($_SESSION['facebook_access_token'])) {
        $accessToken = $_SESSION['facebook_access_token'];
    } else {
        $accessToken = $helper->getAccessToken();
    }
} catch(Facebook\Exceptions\FacebookResponseException $e) {
    // When Graph returns an error
    echo 'Graph returned an error: ' . $e->getMessage();
    exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
    // When validation fails or other local issues
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    exit;
 }
if (isset($accessToken)) {
    if (isset($_SESSION['facebook_access_token'])) {
        $fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
    } else {
        $_SESSION['facebook_access_token'] = (string) $accessToken;
        // OAuth 2.0 client handler
        $oAuth2Client = $fb->getOAuth2Client();
        // Exchanges a short-lived access token for a long-lived one
        $longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($_SESSION['facebook_access_token']);
        $_SESSION['facebook_access_token'] = (string) $longLivedAccessToken;
        $fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
    }

    // validating the access token
    try {
        $request = $fb->get('/me');
    } catch(Facebook\Exceptions\FacebookResponseException $e) {
        // When Graph returns an error
        if ($e->getCode() == 190) {
            unset($_SESSION['facebook_access_token']);
            $helper = $fb->getRedirectLoginHelper();
            //$loginUrl = $helper->getLoginUrl('http://anything.com/fbtest/index.php', $permissions);
            $loginUrl = $helper->getLoginUrl('http://anything.com/page_components/SocialManager/fbtest/index.php', $permissions);
            //$loginUrl = $helper->getLoginUrl('http://anything.com/CZ3003/Web_components/page_components/SocialManager/fbtest/index.php', $permissions);
            echo "<script>window.top.location.href='".$loginUrl."'</script>";
            exit;
        }
    } catch(Facebook\Exceptions\FacebookSDKException $e) {
        // When validation fails or other local issues
        echo 'Facebook SDK returned an error: ' . $e->getMessage();
        exit;
    }

    // posting on user timeline using publish_actins permission
    try {
        // message must come from the user-end
        //$data = ['message' => 'Testing'];
        //$data = ['message' => $data];
        //$data=rand(0,1000);
        $data = ['message' => $data];
        $request = $fb->post('/me/feed', $data);
        $response = $request->getGraphEdge();
    } catch(Facebook\Exceptions\FacebookResponseException $e) {
        // When Graph returns an error
        //comment the line below this to hide errors.
        //echo 'Graph returned an error: ' . $e->getMessage();
        //exit;
    } catch(Facebook\Exceptions\FacebookSDKException $e) {
        // When validation fails or other local issues
        //echo 'Facebook SDK returned an error: ' . $e->getMessage();
        //exit;
    }

    //echo $response['id'];

    // Now you can redirect to another page and use the
    // access token from $_SESSION['facebook_access_token']
} else {
    $helper = $fb->getRedirectLoginHelper();
    //$loginUrl = $helper->getLoginUrl('http://anything.com/fbtest/index.php', $permissions);
    //$loginUrl = $helper->getLoginUrl('http://anything.com/CZ3003/Web_components/page_components/SocialManager/fbtest/index.php', $permissions);
    $loginUrl = $helper->getLoginUrl('http://anything.com/page_components/SocialManager/fbtest/index.php', $permissions);
    echo "<script>window.top.location.href='".$loginUrl."'</script>";
}

0 个答案:

没有答案