PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 26, 2022

[FIXED] Cant post on users timeline

 February 26, 2022     facebook-graph-api, facebook-php-sdk, php     No comments   

Issue

how to post on users timeline using php sdk

i search about that issue on stackoverflow i got nothing plx help i need to do this for my client

   <?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'];

    }




   }



   ?>

Fatal error: Uncaught Facebook\Exceptions\FacebookAuthorizationException: (#200) If posting to a group, requires app being installed in the group, and \ either publish_to_groups permission with user token, or both manage_pages \ and publish_pages permission with page token; If posting to a page, \ requires both manage_pages and publish_pages as an admin with \ sufficient administrative permission in E:\xampp\htdocs\Social_Platform\vendor\facebook\graph-sdk\src\Facebook\Exceptions\FacebookResponseException.php:137 Stack trace: #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 on line 137


Solution

Posting to the user wall is not possible anymore. The required permission "publish_actions" got deprecated a while ago:

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

Use the Share Dialog instead: https://developers.facebook.com/docs/sharing/reference/share-dialog



Answered By - andyrandy
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing