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

awarded to Chlegou
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 8 months 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 8 months ago
Please Hourcem or someone else submit a complete solution.
georgefountain 8 months 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.
Chlegou 8 months 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 8 months ago
Also what should me/feed be replaced with?
georgefountain 8 months 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.
Chlegou 8 months 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 8 months 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
Chlegou 8 months ago
i have to know before if it's ok as implementation first.
Chlegou 8 months ago
Please complete the answer with the photo so I can award you the bounty. Thanks
georgefountain 8 months 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 8 months ago
Please submit a zip file
georgefountain 8 months ago
ah ok then, sure i will look at it by tomorrow. because need to sleep right now. i will submit it by tomorrow
Chlegou 8 months 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 ;)
Chlegou 8 months 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 8 months ago
i told you it gonna work! :p if you liked my works and need further help, you can email me directly on my email, nicolastsue@gmail.com then we can talk ;)
Chlegou 8 months ago
Also, as i said, The twitter one must work perfectly too! :p if no, just email me you have my email ;) but i believe on it! :p it will work perfectly! :p
Chlegou 8 months ago
Houcem, it's working great as I told you :). Not had time to test Twitter yet, I am finishing implementing fb. From your code I get the post ID. I need to progammatically like my own post. This means, have php post into the wall, and auto like it as the page itself. Is this possible? And can you do it? If so, I will create a new bounty. Please let me know. And also is it possible to get insights? (comemnts, number of likes, with a post id?) Thanks!
georgefountain 8 months ago
hi, i will look on that, .. but i haven't verified paypal account, so can't be paid through Paypal from Bountify. can i make it for you and you pay me directly to my Payoneer account if you have one or in Bitcoin BTC ?? please need that help.
Chlegou 8 months ago
I prefer bountify. Contact me directly so we can arrange
georgefountain 8 months ago
Please check if it is possible to code that. If so it will be fantastic! Thank you so much :)
georgefountain 8 months ago
Please check if it is possible to code that. If so it will be fantastic! Thank you so much :)
georgefountain 8 months ago