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

Thursday, January 6, 2022

[FIXED] Facebook graph: Post picture as page not as user

 January 06, 2022     facebook, facebook-graph-api, facebook-php-sdk, php     No comments   

Issue

I'm using FB App to publish posts to my FB pages. So when i use this code for links, it works.

 $facebook = new Facebook(array(
 'appId' => $fb_app_id,
 'secret' => $fb_secret,
 'cookie' => true
));

$attachment =  array(
        'access_token' => $row["token"],
        'name' => $_POST["name"],
        'picture' => $_POST["picture"],
        'message' => $_POST["message"],
        'link' => $_POST["link"]);
    try
    {
        $facebook->api("/".$row['id']."/feed", "POST", $attachment);
    }

    catch(Exception $e)
    {
         echo('exception caught '.$e->getMessage());
    }

But, when i want to share pictures as a page:

$facebook = new Facebook(array(
     'appId' => $fb_app_id,
     'secret' => $fb_secret,
     'cookie' => true,
     'fileUpload' => true,
     'allowSignedRequest' => false 
    ));  

$attachment =  array('access_token' => $row["token"], 'url' => 'http://image.link.jpg', 'message'  => $_POST["message"]);
            try
            {
                $facebook->api("/".$row['id']."/photos", "POST", $attachment);  
            }
            catch(Exception $e)
            {
                echo('exception caught '.$e->getMessage());
            }

The app post picture as user. USER to PAGE. So i found that i need to use publish_pages permission, but my access token contains both publish_actions and publish_pages. I can't change that because I'm using one access token for a lot of things.

enter image description here

So i have to ask, is there a way to explicitly choose what permissions i want to use from access token. FB API have same code for page and user picture publish /user_id/photos and /page_id/photos.


Solution

Need to use Page access token, there's no other way.



Answered By - Aleksa
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

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