【问题标题】:Facebook Php image in text message短信中的 Facebook Php 图片
【发布时间】:2013-01-21 09:55:44
【问题描述】:

在我的页面上,我希望在消息文本中发布带有图像的提要,而不是链接/网址,可以在文本消息中添加类似 htmltagsbbcode 的内容>?

$msg = "<img src=\"urlimg or facebook\" >\nMy text here";

$args = array(
  'message' =>  $mgs,
);

$myfeed = $facebook->api($pageid . '/feed', 'post', $args);

更新:

我找到了解决方案,但如果我连续发布 2 次,它们将被分组在时间轴的同一个框中

$args = array(
'message' =>  $msg,
'image' => '@'.$path,
'aid' => $album_id,
'access_token' => $token
);  
$photo = $facebook->api($album_id . '/photos', 'post', $args);

是否存在停止自动分组的设置?还是有另一种方式来发布它,比如带图片的提要?

【问题讨论】:

    标签: php facebook api post feed


    【解决方案1】:

    你不能在短信中间发布图片,Facebook不允许。

    但你可以在邮件中附加图片,它会以这种方式出现在邮件的左侧:

    $msg = "My text here";
    imgUrl = "http://urltotheimage.com/path/image.jpg";
    
    $args = array(
        'message' => $mgs,
        'picture' => $imgUrl
    );
    
    $myfeed = $facebook->api($pageid . '/feed', 'post', $args);
    

    【讨论】:

    • @Bojangles 的答案是用于将照片上传到相册,而不是用于发布到提要中。不一样。
    【解决方案2】:

    于是我花了 30 秒在 PHP Facebook API 周围搜索,这确实是 应该做的,并找到了以下示例:

    <?
      // Remember to copy files from the SDK's src/ directory to a
      // directory in your application on the server, such as php-sdk/
      require_once('php-sdk/facebook.php');
    
      $config = array(
        'appId' => 'YOUR_APP_ID',
        'secret' => 'YOUR_APP_SECRET',
        'fileUpload' => true,
      );
    
      $facebook = new Facebook($config);
      $user_id = $facebook->getUser();
    
      $photo = './mypic.png'; // Path to the photo on the local filesystem
      $message = 'Photo upload via the PHP SDK!';
    ?>
    <html>
      <head></head>
      <body>
    
      <?
        if($user_id) {
    
          // We have a user ID, so probably a logged in user.
          // If not, we'll get an exception, which we handle below.
          try {
    
            // Upload to a user's profile. The photo will be in the
            // first album in the profile. You can also upload to
            // a specific album by using /ALBUM_ID as the path 
            $ret_obj = $facebook->api('/me/photos', 'POST', array(
                                             'source' => '@' . $photo,
                                             'message' => $message,
                                             )
                                          );
            echo '<pre>Photo ID: ' . $ret_obj['id'] . '</pre>';
    
          } catch(FacebookApiException $e) {
            // If the user is logged out, you can have a 
            // user ID even though the access token is invalid.
            // In this case, we'll get an exception, so we'll
            // just ask the user to login again here.
            $login_url = $facebook->getLoginUrl( array(
                           'scope' => 'photo_upload'
                           )); 
            echo 'Please <a href="' . $login_url . '">login.</a>';
            error_log($e->getType());
            error_log($e->getMessage());
          }   
    
          echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
        } else {
    
          // No user, print a link for the user to login
          // To upload a photo to a user's wall, we need photo_upload  permission
          // We'll use the current URL as the redirect_uri, so we don't
          // need to specify it here.
          $login_url = $facebook->getLoginUrl( array( 'scope' => 'photo_upload') );
          echo 'Please <a href="' . $login_url . '">login.</a>';
    
        }
    
      ?>
    
      </body>
    </html>
    

    记下$config 变量值和$facebook-&gt;api() 调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-16
      • 2014-08-10
      • 2012-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多