Mam profil na Facebooku firmowy oraz prywatny.
Chciałbym zrobić skrypt do automatycznej publikacji postów na moim profilu firmowym.
Mam taki skrypt:
require_once( 'Facebook/autoload.php' ); $fb = new Facebook\Facebook([ 'app_id' => '0000000000000000000', 'app_secret' => '123456789098765432123', 'default_graph_version' => 'v2.5', ]); $helper = $fb->getRedirectLoginHelper(); $permissions = ['email', 'manage_pages ', 'user_photos', 'publish_actions', 'publish_pages', 'pages_manage_instant_articles', 'public_profile', 'user_friends', 'pages_messaging', 'user_posts', 'user_website' ]; $loginUrl = $helper->getLoginUrl($_POST['backurl'], $permissions);
oraz (facebook_create2.php):
require_once( 'Facebook/autoload.php' ); $fb = new Facebook\Facebook([ 'app_id' => '0000000000000000000', 'app_secret' => '123456789098765432123', 'default_graph_version' => 'v2.5', ]); $helper = $fb->getRedirectLoginHelper(); try { $accessToken = $helper->getAccessToken(); } catch(Facebook\Exceptions\FacebookResponseException $e) { // When Graph returns an error exit; } catch(Facebook\Exceptions\FacebookSDKException $e) { // When validation fails or other local issues exit; } try { // Get the Facebook\GraphNodes\GraphUser object for the current user. // If you provided a 'default_access_token', the '{access-token}' is optional. $response = $fb->get('/me?fields=id,name,email,first_name,last_name', $accessToken->getValue()); // print_r($response); } catch(Facebook\Exceptions\FacebookResponseException $e) { // When Graph returns an error exit; } catch(Facebook\Exceptions\FacebookSDKException $e) { // When validation fails or other local issues exit; } $me = $response->getGraphUser(); //print_r($me); echo "Facebook ID: <a href='https://www.facebook.com/".$me->getProperty('id')."' target='_blank'>".$me->getProperty('id')."</a>"."<br>"; $tajny_token = $accessToken; $stmt = $db->prepare("UPDATE cms_admin_firma SET facebook_enable=:facebook_enable, facebook_data=:facebook_data, facebook_token=:facebook_token WHERE gt_id=:gt_id;"); $stmt->bindValue(':facebook_enable', '1', PDO::PARAM_STR); $stmt->bindValue(':facebook_data',($finalna_data), PDO::PARAM_STR); $stmt->bindValue(':facebook_token',($tajny_token), PDO::PARAM_STR); $stmt->bindValue(':gt_id', ($_SESSION['cms_user_id']), PDO::PARAM_INT); $stmt->execute(); $stmt->closeCursor();
Mój kod do dodawania postów (do crona):
$stmt = $db->prepare("SELECT gt_id, facebook_token FROM cms_admin_firma WHERE facebook_enable = '1' and facebook_token <>'';"); $stmt->execute(); foreach ($stmt as $wartt) { require_once(__DIR__.'/Facebook/autoload.php'); 'app_id' => '0000000000000000000', 'app_secret' => '123456789098765432123', 'default_graph_version' => 'v2.5', ); $fb = new Facebook\Facebook($fbData); //// get following data from the db or just replace them //// $title = "Auto Post on Facebook Using PHP SDK v5"; $targetUrl = "https://www.nazwa.pl"; $imgUrl = "https://www.nazwa.pl/images/logo.png"; $description= "opis, opis, opis, opis, opis, opis, opis, opis, opis, opis, opis, opis, opis, opis, opis, opis, opis, opis, opis, opis, opis, opis, opis, "; $params["message"] = $title; $params["link"] = $targetUrl; $params["picture"] = $imgUrl; $params["description"] = $description; // get access token from the database or you can directly put here $access_token = baza_odczyt($wartt['facebook_token']); // post to Facebook try { // Returns a `Facebook\FacebookResponse` object $response = $fb->post('/me/feed', $params, $access_token); } catch(Facebook\Exceptions\FacebookResponseException $e) { exit; } catch(Facebook\Exceptions\FacebookSDKException $e) { exit; } $graphNode = $response->getGraphNode(); }
Skrypt działa super, bez problemu publikuje posty na PRYWATNYM profilu Facebooka.
Chciałbym jednak żeby posty były publikowane na profilu FIRMOWYM.
Jak to zrobić?
Wydaje mi się iż zapisuję w 1 skrypcie token użytkownika prywatnego, nie firmowego - i dlatego posty idą na profil prywatny?
Wiecie może jak naprawić ten problem?
Bardzo proszę o pomoc.
Trifek
ps. nie mam za dużo uprawnień w tej aplikacji?