尝试使用PHP自动发布帖子,我可以发布一个独立的图片,但当它是帖子的一部分时,它没有显示

时间:2015-09-27 12:43:45

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

尝试使用PHP自动发布帖子,我可以发布一个独立的图片,但当它是帖子的一部分时,它没有显示。

以下是我的代码;这是我的第一篇文章,并尽我所能搜索但没有运气。问题是由于我使用的localhost选项吗?

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

include_once ('.\facebook-php-sdk-master\src\facebook.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>

0 个答案:

没有答案