mercredi 29 juin 2016

Trying to automate a post to wall wth PHP, I am able to post a standalone picture but when it is part of a post it is not showing up

Trying to automate a post to wall wth PHP, I am able to post a standalone picture but when it is part of a post it is not showing up.

Below is my code; this is my first post and tried my best to search through but got no luck. Is the issue due to the localhost option I am using?

<html>
<head>
</head>
<body>
<?php

include_once ('.facebook-php-sdk-mastersrcfacebook.php');
$PAGE_ID = ""; // The page you want to post to (you must be a manager)  
$FACEBOOK_APP_ID = "xxx"; // Your facebook app ID
$FACEBOOK_SECRET = "xxx"; // Your facebook secret
$ACCESS_TOKEN="xxx"; // The access token you receieved above
$PAGE_TOKEN = ""; // Leave this blank. It will be set later
$facebook = new Facebook(array(  
'appId'  => $FACEBOOK_APP_ID, 
'secret' => $FACEBOOK_SECRET,  
'cookie' => true,  
));  

$post = array('access_token' => $ACCESS_TOKEN);
try {
$res = $facebook->api('/me/accounts','GET',$post);
print_r($res);
if (isset($res['data'])) {
  foreach ($res['data'] as $account) {
     if ($PAGE_ID == $account['id']) {
        $PAGE_TOKEN = $account['access_token'];
        break;
     }
  }
}
} catch (Exception $e){
echo $e->getMessage();
}
$facebook->setFileUploadSupport(true);

 $loginUrl   = $facebook->getLoginUrl(
        array(

            'scope'         => 'manage_pages,publish_actions,publish_stream,user_photos',
            'redirect_uri'  => 'http://localhost/'

        ));

$photo = $facebook->api('/me/photos', 'POST', 
    array(
        'source' => '@' . realpath('samsonite.jpg'),
        'message' => 'This photo was uploaded via localhost'
    )
);
echo "came here1";
$photoid=$photo['id'];
echo "came here2".$photoid;
print_r($photo);
echo  'http://www.facebook.com/photo.php?fbid='.$photoid;
$args = array(
'message'   => 'message - My First Fbapplication With PHP script1!',
'name' => 'name - Message Posted from kishore!',
'caption'   => 'Test caption!',
    'picture' =>  'http://localhost/samsonite.jpg'   );
$post_id = $facebook->api("/me/feed?access_token=xxx", "post", $args);

?>
</body>
</html>

Aucun commentaire:

Enregistrer un commentaire