S
S
Shenku2016-10-23 14:06:03
Facebook
Shenku, 2016-10-23 14:06:03

Posting on facebook via api?

Good day. Sketched the code for auto-posting in FB

$url = 'https://www.facebook.com/dialog/oauth';

$params = array(
    'client_id'     => $client_id,
    'redirect_uri'  => $redirect_uri,
    'scope' => 'manage_pages,publish_actions,publish_pages'
);

echo $link = '<p><a href="' . $url . '?' . urldecode(http_build_query($params)) . '">Аутентификация через Facebook</a></p>';

if (isset($_GET['code'])) {
    $result = false;

    $params = array(
        'code'  => $_GET['code'],
        'client_id' => $client_id,
        'client_secret' => $client_secret,
        'redirect_uri' => $redirect_uri
    );

    $url = 'https://graph.facebook.com/oauth/access_token';

    $access_token = null;
    parse_str(file_get_contents($url . '?' . http_build_query($params)), $access_token);

    pre($access_token);

    if($access_token['access_token']){
        $params = array(
            'fields' => 'access_token',
            'access_token' => $access_token['access_token']
        );

        $url = 'https://graph.facebook.com/v2.4/'.$page_id;

        $access_token_no_limit = null;
        parse_str(file_get_contents($url . '?' . http_build_query($params)), $access_token_no_limit);

        pre($access_token_no_limit);
    }

}

I receive a 60-day token (as far as I understand) then I send a post
$params = array(
    'access_token' => 'EAARBLjM1vYYBACrFSFTBnUA3NZCZB3HdqvZA7jeW96FKbnWlZByFCAdkK2bfUzvchmJgxNysuxPVFl1WfIpzPCpjG86MU6TwWz6zNaKZAwPq5L3aDGBhw5T9V01AvgyZCi1JZCXAg5ZARMNXEuIonLFpAZAwZC5sZCYpWteU8V9oE9cYQZDZD',
    'message' => '#автопостинг\n\rHello, world! Yooohhooo :)',
    'link' => 'www.caravan.su'
);

$url = 'https://graph.facebook.com/v2.8/'.$page_id.'/feed';

$post = null;
$post = json_decode(file_get_contents($url . '?' . http_build_query($params), true));

pre($post);

but instead of a post, I get a response in the form of already existing posts in the group. Who implemented, please comment. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Philipp, 2016-10-31
@Sh3nku

0. getjump.me/en-php-the-right-way/#%D0%A3%D0%BF%D1%8...
1. Install the Facebook SDK and don't code this horror. https://developers.facebook.com/docs/reference/php
2. Use this example https://developers.facebook.com/docs/php/howto/exa...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question