Automatic Facebook Post Bumper

joshl_1995 4 Tallied Votes 3K Views Share

Hello Daniweb Community,
I have been talking on a couple Facebook groups such as sale pages where you post your own stuff for people to buy. Most groups like this have rules about bumping like once per day, every 12 hours etc...
So it got to the point where it became annoying to have to bump my posts every so oftern so I managed to construct this script that'll do it automatically with the help of a cronjob that can be set to bump at whatever time you like. So I have made a simple easy to use (ha may not easy to understand) script that'll bump and delete the "bump" comment that keep your post clean of exsessive bump comments.

Sorry but I made this a little while ago and forgot how I got my token, so you'll have to "Google" it. Once you've entered your token start gathering your pages.

So this section of the code here

$posts = [
    "PAGE_NAME_GOES_HERE(This is only for your piece of mind knowing what page the ID's are for)" => [
        "POST_ID_ONE",
        "POST_ID_TWO",
        "POST_ID_THREE"
    ],
    "PAGE_NAME_GOES_HERE(This is only for your piece of mind knowing what page the ID's are for)" => [
        "POST_ID_ONE",
        "POST_ID_TWO",
        "POST_ID_THREE"
    ]
];

So as it say the page name is only so you know what page the ID's belong to, now for the POST ID (AKA the permenent link) example look at this link https://www.facebook.com/groups/YOUR_CHOSEN_GROUP/permalink/HERE_IS_THE_POST_ID/ to get the ID on when you look at the post, just under the persons name there is a timestamp. When you click that you'll be redirected to a page and if you look in the address bar there should be a link like the one above. So (for example) if done correctly the snippet above should end up looking like this

$posts = [
    "YOUR_CHOSEN_GROUP" => [
        "HERE_IS_THE_POST_ID1",
        "HERE_IS_THE_POST_ID2",
        "HERE_IS_THE_POST_ID3"
    ]
];

I hope this is understandable, any questions comment below (or if you saw this on Facebook just comment on my post of PM me).

Attention
If you happen to get stuck with setting this up, or have any questions please let me know below and I may be able to assist you.

To Facebook Users (That I probably brought here)
This may all be new to you and may not know the first thing about website development, so if you are interested in using this. Comment below or let me know back on Facebook.

<?php
	$posts = [
		"PAGE_NAME_GOES_HERE(This is only for your piece of mind knowing what page the ID's are for)" => [
			"POST_ID_ONE",
			"POST_ID_TWO",
			"POST_ID_THREE"
		],
		"PAGE_NAME_GOES_HERE(This is only for your piece of mind knowing what page the ID's are for)" => [
			"POST_ID_ONE",
			"POST_ID_TWO",
			"POST_ID_THREE"
		]
	];
	
	$bumpResults = ['Notify' => 'yes', 'PageResults' => 'No Result', 'Errors' => 'Nothing was processed!'];
	
	if (!empty($posts)) {
		$accessToken = "TOKEN_GOES_HERE";
		
		foreach ($posts as $page => $ids) {
			$bumpResult = BumpPost("bump", $accessToken, $ids);
			if (is_array($bumpResult) && !isset($bumpResult['error'])) {
				$removalResult = BumpPost("removeBump", $accessToken, $bumpResult);
				foreach ($removalResult as $key => $value) {
					switch ($value) {
						case "successRemove":
							@$bumpResults['PageResults'][$page]['success'][$key] = "Post: #".$key." was successfully bumped!";
							if ($bumpResults['Notify'] != "yes") { $bumpResults['Notify'] = "no"; }
						break;
						case "failedBump":
							$bumpResults['PageResults'][$page]['fails'][$key] = "Post: #".$key." failed to bump!";
							$bumpResults['Notify'] = "yes";
						break;
						case "failedRemove":
							$key = explode(">", $key);
							$bumpResults['PageResults'][$page]['fails'][$key[1]] = "Post: #".$key[1]." was bumped but failed to remove comment: #".$key[0]." !";
							$bumpResults['Notify'] = "yes";
						break;
						case "error":
						default:
							$bumpResults['PageResults'][$page]['error'][] = $key;
							$bumpResults['Notify'] = "yes";
						break;
					}
				}
			} else if (is_array($bumpResult) && isset($bumpResult['error'])) {
				$bumpResults['Errors'][] = $bumpResult['error'];
				$bumpResults['Notify'] = "yes";
			} else {
				$bumpResults['Errors'][] = "An error has occurred!";
				$bumpResults['Notify'] = "yes";
			}
		}
	} else {
		$bumpResults['Errors'][] = "There are no posts to bump.";
		$bumpResults['Notify'] = "yes";
	}
	
	if ($bumpResults['Notify'] == "yes") {
		echo "<pre>";
		print_r($bumpResults);
		echo "</pre>";
	}
	
	function BumpPost($action, $accessToken, $ids) {
		$params = ["access_token" => $accessToken];
		$results = [];
		$fixedIDs = [];
		
		if ($action == "removeBump") {
			foreach ($ids as $id => $result) {
				switch ($result) {
					case "successBump":
						$fixedIDs[] = $id;
					break;
					case "failedBump":
						$results[$id] = $result;
					break;
				}
			}
		}
		else
			$fixedIDs = $ids;
		
		if (!empty($fixedIDs)) {
			foreach ($fixedIDs as $id) {
				switch ($action) {
					case "bump":
						$id .= "/comments";
						$params['message'] = "Bump!";
					break;
					case "removeBump":
						$id = explode(">", $id);
						$params['method'] = "delete";
					break;
				}
				
				if (($action === "bump" || $action === "removeBump") && count($params) > 1) {
					$ch = curl_init();
					curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/v2.2/".(($action === "bump") ? $id : $id[0]));
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
					curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
					curl_setopt($ch, CURLOPT_POST, true);
					curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
					curl_setopt($ch, CURLOPT_HEADER, 0);
					curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
					$comment = curl_exec($ch);
					curl_close($ch);
					$comment = json_decode($comment, true);
					
					switch ($action) {
						case "bump":
							$results[((isset($comment['id'])) ? $comment['id'].">".rtrim($id, "/comments") : rtrim($id, "/comments"))] = ((count($comment) === 1 && isset($comment['id'])) ? "successBump" : "failedBump");
						break;
						case "removeBump":
							$results[((isset($comment['success'])) ? $id[1] : $id[0].">".$id[1])] = ((count($comment) === 1 && isset($comment['success'])) ? "successRemove" : "failedRemove");
						break;
					}
				} else {
					$results["Post failed to be processed!"] = "error";
				}
			}
		} else if (empty($fixedIDs) && count(array_keys($fixedIDs, "failedBump")) != count($fixedIDs)) {
			$results['No IDs were passed.'] = "error";
		}
		
		return $results;
	}
?>
Lucas_7 0 Newbie Poster

hello mate, sorry for my ignorance but how can i run this script ?

joshl_1995 22 Twisted Digital

Hello,
This script can either be ran locally on a computer using a program such as Wamp or even run it on a server like on a website then just run a Cronjob to execute it.

A cheap solution to this is registering with a free PHP website host then putting the script on there and just Google that basics of how to setup a Cronjob.

Lucas_7 0 Newbie Poster

Could u help me with the facebook token, and how could i get it ? i have seen many options for the token but which one is the right?

joshl_1995 22 Twisted Digital

I've posted another Facebook related code snippet here which contains a guide on how to obtain an api key [HERE]

Lucas_7 0 Newbie Poster

ok, i got the token, the permalinks id's ,the script, the cronjob, but isnt working when i try to "view" the script on the file manager i get the 404 page of the free host (should this happen?).
[To edit the script i used notepad++, then saved as .php, uploaded with the file manager]
heres the script:

<?php
    $posts = [
        "br-csgo" => [
            "565167146975015",
            "POST_ID_TWO",
            "POST_ID_THREE"
        ],
        "csnetwork" => [
            "1727257750831063",
            "494510417393925",
            "POST_ID_THREE"
        ]
    ];

    $bumpResults = ['Notify' => 'yes', 'PageResults' => 'No Result', 'Errors' => 'Nothing was processed!'];

    if (!empty($posts)) {
        $accessToken = "1106227486057176|xxxxxxxxxxxxxxxxxxxxxxxxuyE";

        foreach ($posts as $page => $ids) {
            $bumpResult = BumpPost("bump", $accessToken, $ids);
            if (is_array($bumpResult) && !isset($bumpResult['error'])) {
                $removalResult = BumpPost("removeBump", $accessToken, $bumpResult);
                foreach ($removalResult as $key => $value) {
                    switch ($value) {
                        case "successRemove":
                            @$bumpResults['PageResults'][$page]['success'][$key] = "Post: #".$key." was successfully bumped!";
                            if ($bumpResults['Notify'] != "yes") { $bumpResults['Notify'] = "no"; }
                        break;
                        case "failedBump":
                            $bumpResults['PageResults'][$page]['fails'][$key] = "Post: #".$key." failed to bump!";
                            $bumpResults['Notify'] = "yes";
                        break;
                        case "failedRemove":
                            $key = explode(">", $key);
                            $bumpResults['PageResults'][$page]['fails'][$key[1]] = "Post: #".$key[1]." was bumped but failed to remove comment: #".$key[0]." !";
                            $bumpResults['Notify'] = "yes";
                        break;
                        case "error":
                        default:
                            $bumpResults['PageResults'][$page]['error'][] = $key;
                            $bumpResults['Notify'] = "yes";
                        break;
                    }
                }
            } else if (is_array($bumpResult) && isset($bumpResult['error'])) {
                $bumpResults['Errors'][] = $bumpResult['error'];
                $bumpResults['Notify'] = "yes";
            } else {
                $bumpResults['Errors'][] = "An error has occurred!";
                $bumpResults['Notify'] = "yes";
            }
        }
    } else {
        $bumpResults['Errors'][] = "There are no posts to bump.";
        $bumpResults['Notify'] = "yes";
    }

    if ($bumpResults['Notify'] == "yes") {
        echo "<pre>";
        print_r($bumpResults);
        echo "</pre>";
    }

    function BumpPost($action, $accessToken, $ids) {
        $params = ["access_token" => $accessToken];
        $results = [];
        $fixedIDs = [];

        if ($action == "removeBump") {
            foreach ($ids as $id => $result) {
                switch ($result) {
                    case "successBump":
                        $fixedIDs[] = $id;
                    break;
                    case "failedBump":
                        $results[$id] = $result;
                    break;
                }
            }
        }
        else
            $fixedIDs = $ids;

        if (!empty($fixedIDs)) {
            foreach ($fixedIDs as $id) {
                switch ($action) {
                    case "bump":
                        $id .= "/comments";
                        $params['message'] = "Bump!";
                    break;
                    case "removeBump":
                        $id = explode(">", $id);
                        $params['method'] = "delete";
                    break;
                }

                if (($action === "bump" || $action === "removeBump") && count($params) > 1) {
                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/v2.2/".(($action === "bump") ? $id : $id[0]));
                    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
                    curl_setopt($ch, CURLOPT_POST, true);
                    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
                    curl_setopt($ch, CURLOPT_HEADER, 0);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                    $comment = curl_exec($ch);
                    curl_close($ch);
                    $comment = json_decode($comment, true);

                    switch ($action) {
                        case "bump":
                            $results[((isset($comment['id'])) ? $comment['id'].">".rtrim($id, "/comments") : rtrim($id, "/comments"))] = ((count($comment) === 1 && isset($comment['id'])) ? "successBump" : "failedBump");
                        break;
                        case "removeBump":
                            $results[((isset($comment['success'])) ? $id[1] : $id[0].">".$id[1])] = ((count($comment) === 1 && isset($comment['success'])) ? "successRemove" : "failedRemove");
                        break;
                    }
                } else {
                    $results["Post failed to be processed!"] = "error";
                }
            }
        } else if (empty($fixedIDs) && count(array_keys($fixedIDs, "failedBump")) != count($fixedIDs)) {
            $results['No IDs were passed.'] = "error";
        }

        return $results;
    }
?>
joshl_1995 22 Twisted Digital

Well if it's getting a 404 that wouldn't have anything to do with the script, either it didn't upload to the server of your searching for it in the wrong directory.

Lucas_7 0 Newbie Poster

With WAMP i'm getting this error:
WAMP.jpg

script:

<?php
    $posts = [
        "GROUP1" => [
            "565167146975015",
            "POST_ID_TWO",
            "POST_ID_THREE"
        ],
        "GROUP2" => [
            "1727257750831063",
            "POST_ID_TWO",
            "POST_ID_THREE"
        ],
        "GROUP3" => [
            "494510417393925",
            "POST_ID_TWO",
            "POST_ID_THREE"
        ]
    ];

    $bumpResults = ['Notify' => 'yes', 'PageResults' => 'No Result', 'Errors' => 'Nothing was processed!'];

    if (!empty($posts)) {
        $accessToken = "1106227486057176|9SnNQUiP09SjWKpN29jYIgG3uyE";

        foreach ($posts as $page => $ids) {
            $bumpResult = BumpPost("bump", $accessToken, $ids);
            if (is_array($bumpResult) && !isset($bumpResult['error'])) {
                $removalResult = BumpPost("removeBump", $accessToken, $bumpResult);
                foreach ($removalResult as $key => $value) {
                    switch ($value) {
                        case "successRemove":
                            @$bumpResults['PageResults'][$page]['success'][$key] = "Post: #".$key." was successfully bumped!";
                            if ($bumpResults['Notify'] != "yes") { $bumpResults['Notify'] = "no"; }
                        break;
                        case "failedBump":
                            $bumpResults['PageResults'][$page]['fails'][$key] = "Post: #".$key." failed to bump!";
                            $bumpResults['Notify'] = "yes";
                        break;
                        case "failedRemove":
                            $key = explode(">", $key);
                            $bumpResults['PageResults'][$page]['fails'][$key[1]] = "Post: #".$key[1]." was bumped but failed to remove comment: #".$key[0]." !";
                            $bumpResults['Notify'] = "yes";
                        break;
                        case "error":
                        default:
                            $bumpResults['PageResults'][$page]['error'][] = $key;
                            $bumpResults['Notify'] = "yes";
                        break;
                    }
                }
            } else if (is_array($bumpResult) && isset($bumpResult['error'])) {
                $bumpResults['Errors'][] = $bumpResult['error'];
                $bumpResults['Notify'] = "yes";
            } else {
                $bumpResults['Errors'][] = "An error has occurred!";
                $bumpResults['Notify'] = "yes";
            }
        }
    } else {
        $bumpResults['Errors'][] = "There are no posts to bump.";
        $bumpResults['Notify'] = "yes";
    }

    if ($bumpResults['Notify'] == "yes") {
        echo "<pre>";
        print_r($bumpResults);
        echo "</pre>";
    }

    function BumpPost($action, $accessToken, $ids) {
        $params = ["access_token" => $accessToken];
        $results = [];
        $fixedIDs = [];

        if ($action == "removeBump") {
            foreach ($ids as $id => $result) {
                switch ($result) {
                    case "successBump":
                        $fixedIDs[] = $id;
                    break;
                    case "failedBump":
                        $results[$id] = $result;
                    break;
                }
            }
        }
        else
            $fixedIDs = $ids;

        if (!empty($fixedIDs)) {
            foreach ($fixedIDs as $id) {
                switch ($action) {
                    case "bump":
                        $id .= "/comments";
                        $params['message'] = "Bump!";
                    break;
                    case "removeBump":
                        $id = explode(">", $id);
                        $params['method'] = "delete";
                    break;
                }

                if (($action === "bump" || $action === "removeBump") && count($params) > 1) {
                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/v2.2/".(($action === "bump") ? $id : $id[0]));
                    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
                    curl_setopt($ch, CURLOPT_POST, true);
                    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
                    curl_setopt($ch, CURLOPT_HEADER, 0);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                    $comment = curl_exec($ch);
                    curl_close($ch);
                    $comment = json_decode($comment, true);

                    switch ($action) {
                        case "bump":
                            $results[((isset($comment['id'])) ? $comment['id'].">".rtrim($id, "/comments") : rtrim($id, "/comments"))] = ((count($comment) === 1 && isset($comment['id'])) ? "successBump" : "failedBump");
                        break;
                        case "removeBump":
                            $results[((isset($comment['success'])) ? $id[1] : $id[0].">".$id[1])] = ((count($comment) === 1 && isset($comment['success'])) ? "successRemove" : "failedRemove");
                        break;
                    }
                } else {
                    $results["Post failed to be processed!"] = "error";
                }
            }
        } else if (empty($fixedIDs) && count(array_keys($fixedIDs, "failedBump")) != count($fixedIDs)) {
            $results['No IDs were passed.'] = "error";
        }

        return $results;
    }
?>
joshl_1995 22 Twisted Digital

Hello,
Try changing this line $bumpResults['PageResults'][$page]['fails'][$key] = "Post: #".$key." failed to bump!"; to @$bumpResults['PageResults'][$page]['fails'][$key] = "Post: #".$key." failed to bump!"; and just see if that works

Lucas_7 0 Newbie Poster

Hello,
on wamp it just lead in to a blank white page.

on
the free hosting it gets this error:
php.jpg

there's a easy way that i can contact you?

joshl_1995 22 Twisted Digital

I'll start a live chat

joshl_1995 22 Twisted Digital

Ok never mind just another thing stuffed up about the new Daniweb I can't seem to find a way to live chat someone. Nevermind, when you're trying the script online are the 'POST_ID_TWO' and 'POST_ID_THREE' still there? if so try removing them, so removing them will look like this

    $posts = [
        "GROUP1" => [
            "565167146975015"
        ],
        "GROUP2" => [
            "1727257750831063"
        ],
        "GROUP3" => [
            "494510417393925"
        ]
    ];
Lucas_7 0 Newbie Poster

same error
script:
http://pastebin.com/EKbTgzp2

:(

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

if you're using an old version of PHP, lower than 5.4 then change the array syntax to:

$posts = array();

Starting from PHP 5.4 you can use the short syntax:

$posts = [];

So the array should look like:

$posts = array(
    "GROUP1" => array(
        "565167146975015"
    ),
    "GROUP2" => array(
        "1727257750831063"
    ),
    "GROUP3" => array(
        "494510417393925"
    )
);

Upgrade whenever is possible :)

Lucas_7 0 Newbie Poster

Hi Cereal ,
WAMP is 5.5.12, the free hosting is 5.2
do u have to change (the array thing) in all the script?
because i changed that part that you mencioned, but i still got a blank page on WAMP and still a syntax error on the server(but this time in line 13 ).

cereal 1,524 Nearly a Senior Poster Featured Poster

do u have to change (the array thing) in all the script?

Yes, from what I've seen you have to change line 13 and then from 60 to 62.

Lucas_7 0 Newbie Poster

but in WAMP it should have it worked right?

edit: i did the array thing now both WAMP and the server leads to a blank page :(

cereal 1,524 Nearly a Senior Poster Featured Poster

but in WAMP it should have it worked right? [...] now both WAMP and the server leads to a blank page

I haven't tested Josh's script, I replied only to explain why you were getting the syntax error. Have you tried to change the access token? The value hardcoded in the original script is valid only for Josh, not for you.

Lucas_7 0 Newbie Poster

The value hardcoded in the original script is valid only for Josh

this one is actually mine.

1106227486057176|9SnNQUiP09SjWKpN29jYIgG3uyE
joshl_1995 22 Twisted Digital

Sorry for taking a while to reply, I've been busy. So with fixing up the array to use the previous version array(...) function what error are you getting?

Lucas_7 0 Newbie Poster

So with fixing up the array to use the previous version array(...) function what error are you getting?

blank white page, only

joshl_1995 22 Twisted Digital

And is there any error logs?

Lucas_7 0 Newbie Poster

where would they be located at at wamp ? i found a txt called "php_error" but there's nothing there

joshl_1995 22 Twisted Digital

Sorry I totally forgot to reply, are there any errors on the server?

Also if you like you can PM me the raw code used on the server you can blank out the key if you like doesn't matter but I can have a propper look at the exact code you are using. I was thinking of making this into a service but not many people supported it (which would make things easier but doesn't matter)

nickburrett 0 Newbie Poster

I just get a blank page, is there any way I can get some feedback as to whether the script is working or not?

Kenneth_7 0 Newbie Poster

This code fails to bump every time. I am not getting any feedback in order to solve it. It does not even get past the first post though.

joshl_1995 22 Twisted Digital

Hello Everyone,
I'm currently in the process of working this out, however I honestly don't think there is anything that I can do as the code works. The problem is within Facebook's API, I've noticed I cannot access comments like I could before. So I have no idea how to get this working, if I can post a comment using the API then the rest will all work. So if anyone can figure this out, you'll be a code hero!

Thomas_40 0 Newbie Poster

Hi there, I now I am commenting a long time after this was released but it would really help me. Does it still work? Thanks!

joshl_1995 22 Twisted Digital

Hello Thomas_40,
I've had a look into getting this working again but have failed. However at the time of lookinf into getting it working again was when I've been busy. I'm planning on looking deeper into it once I'm not so busy. So there may still be a chance, I'll keep anyone posted on here.

Б. 0 Newbie Poster

Any news? All alternatives are paid :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.