Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- session_start();
- date_default_timezone_set('Europe/Paris');
- define('FACEBOOK_SDK_V4_SRC_DIR', '/fb-php-sdk-v4/src/Facebook/');
- require __DIR__ . '/facebook-php-sdk-v4/autoload.php';
- require_once( __DIR__ . '/facebook-php-sdk-v4/src/Facebook/FacebookSession.php' );
- require_once( __DIR__ . '/facebook-php-sdk-v4/src/Facebook/FacebookRedirectLoginHelper.php' );
- require_once( __DIR__ . '/facebook-php-sdk-v4/src/Facebook/FacebookRequest.php' );
- require_once( __DIR__ . '/facebook-php-sdk-v4/src/Facebook/FacebookResponse.php' );
- require_once( __DIR__ . '/facebook-php-sdk-v4/src/Facebook/FacebookSDKException.php' );
- require_once( __DIR__ . '/facebook-php-sdk-v4/src/Facebook/FacebookRequestException.php' );
- require_once( __DIR__ . '/facebook-php-sdk-v4/src/Facebook/FacebookAuthorizationException.php' );
- require_once( __DIR__ . '/facebook-php-sdk-v4/src/Facebook/GraphObject.php' );
- require_once( __DIR__ . '/facebook-php-sdk-v4/src/Facebook/Entities/AccessToken.php' );
- require_once( __DIR__ . '/facebook-php-sdk-v4/src/Facebook/HttpClients/FacebookHttpable.php' );
- require_once( __DIR__ . '/facebook-php-sdk-v4/src/Facebook/HttpClients/FacebookCurlHttpClient.php' );
- require_once( __DIR__ . '/facebook-php-sdk-v4/src/Facebook/HttpClients/FacebookCurl.php' );
- use Facebook\FacebookSession;
- use Facebook\FacebookRedirectLoginHelper;
- use Facebook\FacebookRequest;
- use Facebook\FacebookResponse;
- use Facebook\FacebookSDKException;
- use Facebook\FacebookRequestException;
- use Facebook\FacebookAuthorizationException;
- use Facebook\GraphObject;
- use Facebook\Entities\AccessToken;
- use Facebook\HttpClients\FacebookHttpable;
- use Facebook\HttpClients\FacebookCurlHttpClient;
- use Facebook\HttpClients\FacebookCurl;
- FacebookSession::setDefaultApplication('XXXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); // app_id et app_secret de l'application Facebook
- // facebook_publish()
- // $page_id = id de la page facebook au nom de laquelle on veut publier
- // $access_token = access token valide pour la page
- // $publish_timestamp = timestamp de l'heure programmée de publication, entre 10 minutes et 6 mois (facultatif)
- // $message = message posté (facultatif si on partage un lien)
- // $link = lien partagé (facultatif si on a mis un message)
- // $link_name = titre du lien (possible si lien partagé)
- // $link_description = description du lien (possible si lien partagé)
- function facebook_publish($page_id,$access_token,$publish_timestamp=false,$message='',$link='',$link_name='',$link_description='')
- {
- if (!$page_id or !$access_token or (!$message and !$link))
- return array('error'=>'You must provide at lease a page_id, an access_token and a message or a link.');
- $session = new FacebookSession($access_token);
- $request = new FacebookRequest
- (
- $session,
- 'POST',
- '/'.$page_id.'/feed',
- array
- (
- 'published' => ($publish_timestamp)?false:true,
- 'scheduled_publish_time' => ($publish_timestamp)?$publish_timestamp:false,
- 'message' => $message,
- 'link' => $link,
- 'name' => $link_name,
- 'description' => $link_description
- )
- );
- try
- {
- $response = $request->execute();
- $graphObject = $response->getRawResponse();
- return $graphObject; // si la requête ok, retourne {"id":"XXXXXXXXXXX_XXXXXXXXXXXXXXXXX"}
- }
- catch(Exception $e)
- {
- return $e;
- }
- }
- // facebook_delete()
- // $post_id = id du post facebook à supprimer sous la forme XXXXXXXXXXX_XXXXXXXXXXXXXXXXX
- // $access_token = assess token valide pour la page
- function facebook_delete($post_id,$access_token)
- {
- $session = new FacebookSession($access_token);
- $request = new FacebookRequest
- (
- $session,
- 'DELETE',
- '/'.$post_id
- );
- try
- {
- $response = $request->execute();
- $graphObject = $response->getRawResponse();
- return $graphObject; // si la requête ok, retourne {"success":true}
- }
- catch(Exception $e)
- {
- return $e;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement