3

我正在尝试开发一个应该将新闻提要发送到网站的 fb 应用程序;

我设法使用 app_id 和 app_secret 订阅,但我没有收到新闻提要;

public function actionSubscription() {
        $app_id = '691036934243090';
        $app_secret = 'ca6e828f41c638dba4fb0864f7d9f6e8';
        $app_url = 'http://www.ghidul-comercial.ro';
        $fields = 'feed';
        $verify_token = 'blabla';

        // Fetching an App Token
        $app_token_url = 'https://graph.facebook.com/oauth/access_token?client_id='
                . $app_id . '&client_secret=' . $app_secret
                . '&grant_type=client_credentials';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $app_token_url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $res = curl_exec($ch);
        parse_str($res, $token);

        if (isset($token['access_token'])) {
            // Let's register a callback
            $params = array(
                'object'
                => 'page',
                'fields'
                => $fields,
                'callback_url'
                // This is the endpoint that will be called when
                // a User updates the location field
                => $app_url . '/index.php/site/api',
                'verify_token'
                => $verify_token,
            );

            curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/'
                    . $app_id . '/subscriptions?access_token='
                    . $token['access_token']);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
            $res = curl_exec($ch);
            if ($res && $res != 'null') {
                print_r($res);
            }

            // Fetch list of all callbacks
            curl_setopt($ch, CURLOPT_POST, 0);
            $res = curl_exec($ch);
        }
        if ($res && $res != 'null') {
            print_r($res);
        }
        curl_close($ch);
        error_log('test');
    }

这就是我打算捕捉提要的方式:

public function actionApi() {
    $data = new Data();
    $data->info = '1';
    $data->save(false);

    $method = $_SERVER['REQUEST_METHOD'];
    $data = new Data();
    $data->info = $method;
    $data->save(false);

    $rawdata1 = file_get_contents('php://input');
    $rawdata2 = json_decode($HTTP_RAW_POST_DATA,true);
    $rawdata2 = json_decode(file_get_contents('php://input'),true);


    $data = new Data();
        $data->info = $rawdata1;
        $data->save(false);

    if ($method == 'GET' && isset($_GET['hub_mode']) && $_GET['hub_mode'] == 'subscribe' && isset($_GET['hub_verify_token']) && $_GET['hub_verify_token'] == 'blabla') {
        echo $_GET['hub_challenge'];
        exit;
    } elseif ($method == 'POST') {
        $post = file_get_contents("php://input");
        $data = new Data();
        $data->info = $post;
        $data->save(false);
    }

    $data = new Data();
    $data->info = '2';
    $data->save(false);
}
4

1 回答 1

2

转到链接单击Get Access Token,通过单击从 3 个选项卡中选择所有内容,单击获取访问令牌,然后粘贴您的组 ID;也在您的提要字段中,然后单击提交。

就这样 !这会起作用

于 2013-08-29T12:13:07.020 回答