无法在用户时间轴上发布信息

时间:2019-10-01 19:07:44

标签: php facebook-graph-api facebook-php-sdk

如何使用php sdk在用户时间线上发布

我在stackoverflow上搜索了该问题,但没有得到任何帮助 我需要为我的客户做

   <?php
   namespace App;

   use Facebook\Facebook;

   class FacebookClass{
   private $fb;
   private $appiD = 3073019182770120;
   private $appSecret = "6360e1540e1add2b6fc93fce07fcb61a";

   public function __construct()
   {
    $this->fb = new Facebook([
        'app_id' => $this->appiD, // Replace {app-id} with your app id
        'app_secret' => $this->appSecret,
        'default_graph_version' => 'v4.0',
    ]);
   }

   public function getLoginUrl() {
    $helper = $this->fb->getRedirectLoginHelper();
    $permissions = ['email']; // Optional permissions
    $loginUrl = $helper- 
   >getLoginUrl('http://localhost/social_platform/',$permissions);

    return $loginUrl;
    }

   public function loginWithFacebook() {
   $helper = $this->fb->getRedirectLoginHelper();
   try {
   $accessToken = $helper->getAccessToken();
   if(isset($accessToken))
   {
    $_SESSION['facebook']['access_token'] = (string) $accessToken;

    header("index.php");
   }
   } catch (\Throwable $th) {
// var_dump($th);
   }
   }

   public function postOnUserTimeLine() {


    // posting on user timeline using publish_actins permission
    try {
        // message must come from the user-end
        $data = ['message' => 'testing...'];
        $request = $this->fb->post('/me/feed', $data, 
         $_SESSION['facebook']['access_token']);
        $response = $request->getGraphNode()->asArray;
    } catch (Facebook\Exceptions\FacebookResponseException $e) {
        // When Graph returns an error
        echo 'Graph returned an error: ' . $e->getMessage();
        exit;
    } catch (Facebook\Exceptions\FacebookSDKException $e) {
        // When validation fails or other local issues
        echo 'Facebook SDK returned an error: ' . $e->getMessage();
        exit;
    }
    echo $response['id'];

    }




   }



   ?>

致命错误:未捕获Facebook \ Exceptions \ FacebookAuthorizationException:(#200)如果发布到网上论坛,需要在该网上论坛中安装应用,并且\要么带有用户令牌的publish_to_groups权限,要么带有页面令牌的manage_pages \和publish_pages权限;如果要发布到页面,则\要求具有\\在E:\ xampp \ htdocs \ Social_Platform \ vendor \ facebook \ graph-sdk \ src \ Facebook \ Exceptions \ FacebookResponseException.php:137堆栈中具有足够的管理权限的管理员作为manage_pages和publish_pages跟踪:#0 E:\ xampp \ htdocs \ Social_Platform \ vendor \ facebook \ graph-sdk \ src \ Facebook \ FacebookResponse.php(210):Facebook \ Exceptions \ FacebookResponseException :: create(Object(Facebook \ FacebookResponse))#1 E:\ xampp \ htdocs \ Social_Platform \ vendor \ facebook \ graph-sdk \ src \ Facebook \ FacebookResponse.php(255):Facebook \ FacebookResponse-> makeException()#2 E:\ xampp \ htdocs \ Social_Platform \ vendor \ facebook \ graph-sdk \ src \ Facebook \ FacebookResponse.php(82):Facebook \ FacebookResponse-> deco in E:\ xampp \ htdocs \ Social_Platform \ vendor \ facebook \ graph-sdk \ src \ Facebook \ Exceptions \ FacebookResponseException.php 137行

1 个答案:

答案 0 :(得分:0)

无法再发布到用户墙上。所需的权限“ publish_actions”在不久前已被弃用:

https://developers.facebook.com/docs/graph-api/changelog/breaking-changes#login-4-24

改为使用“共享”对话框:https://developers.facebook.com/docs/sharing/reference/share-dialog