Php Automatically post to Facebook fan page
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Simple.

I need a php script that will post to my Facebook fan page.
Two functions are needed:

A) public static function postImage(text, image Url, ...)

B) public static function postLink(text, href, imageUrl,..)

  • Code must be written in a class, very organized.
  • Code should handle auth with facebook, tokens, or whatever is needed automatically, without user intervention
  • Code should not use Composer, assume all dependency files are on folder.
  • Complete zip file with all Facebook libraries and needed files should be provided including instructions on how to configure and setup.

Environment: Php 5.6

Tags
PHP

Crowdsource coding tasks.

1 Solution

Winning solution

Hi again, so facebook isn't easy as Twitter, but that what i came with:

1 . you need first to download the Facebook library SDK from github.

Link: https://github.com/facebook/facebook-php-sdk-v4/archive/5.0.0.zip

2 . create your app and your unexpired link. then connect them together. Facebook is very sensitive to changes and integration, so i suggest using the whole code in a bunch to making classes like i did with twitter. i also like Oriented Object Programming, but little bit aware that it will not work with you because i'm not testing them.

3 . your code should be like that:

require_once('/right/path/to/Facebook/autoload.php');

$fb = new Facebook\Facebook([
 'app_id' => 'xxxxxxxxxx',
 'app_secret' => 'xxxxxxxxxx',
 'default_graph_version' => 'v2.2',
]);


//this token have to be generated by an created address!!!
$pageAccessToken ='your_non_expiring_token';

//Post property to Facebook
$linkData = [
 'link' => 'www.yoururl.com',
 'message' => 'Your message here'
];


try {
 $response = $fb->post('/me/feed', $linkData, $pageAccessToken);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
 echo 'Graph returned an error: '.$e->getMessage();
 exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
 echo 'Facebook SDK returned an error: '.$e->getMessage();
 exit;
}
$graphNode = $response->getGraphNode();

4 . you can follow this tutorial, will help you to create your app, also your unexpired token and integrating the whole code.

link: https://goo.gl/6abqHj

Can you please add photo to the post? And can you deliver a zip file with all files and test it?
georgefountain 9 days ago
I really need you to test this. Before posting on bountify I have read dozens of articles. All the implementations are different and most people comment they don't work. I also read this article before. Pleas test it and submit a zip file so I can grant you the bounty. Thanks
georgefountain 9 days ago
Please Hourcem or someone else submit a complete solution.
georgefountain 8 days ago
as i said, i haven't an app tokens, so why you just don't give it a try, and if you get some errors, just get back to me?? even for the twitter, the same.
Houcem B. A. Chlegou 7 days ago
Ok I can test the Twitter but this solution is incomplete. Can you add the photo? There is no photo on this post function. Thanks
georgefountain 7 days ago
Also what should me/feed be replaced with?
georgefountain 7 days ago
as i said, on twitter bounty, i like to separate your part and the scripting part. so all you have to set is, the: //Post property to Facebook $linkData = [ 'link' => 'www.yoururl.com', 'message' => 'Your message here' ]; you don't have to do any other things! the "/me/feed" it's for FB posting directory (or tree) you have nothing to do with. $linkData is the only thing to change so. try to give a try for both of scripts and give feedback. the twitter may work perfectly! if you get any error on these, contact me.
Houcem B. A. Chlegou 6 days ago
What about the photo? Let's say I want to add a custom photo with the link. How do I add it? Thanks
georgefountain 6 days ago
then it will be like that: $linkData = [ 'link' => 'www.yoururl.com', 'message' => 'Your message here', 'photo' => 'path/to/photo.jpg' ]; That simple! :p you are wasting time like that. the most important thing is to give it a try to see what response you have got. try first with twitter because it's easy to work with, then we will fix the fb
Houcem B. A. Chlegou 6 days ago
i have to know before if it's ok as implementation first.
Houcem B. A. Chlegou 6 days ago
Please complete the answer with the photo so I can award you the bounty. Thanks
georgefountain 2 days ago
Bountify tells me I got about 36 hs to decide to whom to award the bounty. Please complete so I can award it to you .Thank you!
georgefountain 2 days ago
Please submit a zip file
georgefountain 2 days ago
ah ok then, sure i will look at it by tomorrow. because need to sleep right now. i will submit it by tomorrow
Houcem B. A. Chlegou 2 days ago
Ok, here is the bounty final work! ;) i have make it working, from the Facebook developer website! :D it's fine right now, and it must work 100% perfectly! :D file as required, uploaded to drive. follow instruction to install FB SDK from github (you will find links in file), then use my code ;) here is the link: https://drive.google.com/open?id=0B2wCjF-lIcvpQzF4eTJnYXRvSzA enjoy ;)
Houcem B. A. Chlegou 2 days ago
It worked well finally! Creating the non-expiring token was almost "mission impossible"... but I made it :) Thanks. Now I need to test out twitter's which seems simpler!
georgefountain 2 hours ago