【问题标题】:Post a picture to a facebook wall将图片发布到 Facebook 墙上
【发布时间】:2011-05-29 10:00:35
【问题描述】:

我无法发布 Facebook 墙的链接。这就像它应该的那样工作,只有我尝试附加到它的图像不会显示在页面上。

我必须做一些特别的事情来发布图片吗?

public function shareAction()
{
    include_once('/application/modules/social/services/facebook/facebook.php');

    $request = $this->getRequest();
    $this->_helper->getHelper('viewRenderer')->setNoRender();
    $this->_helper->getHelper('layout')->disableLayout();

    $return = 'ERROR';

    if($request->isPost()) {
        $file   = TOMATO_APP_DIR . DS . 'modules' . DS . 'social' . DS . 'config' . DS . 'config.ini';
  $config = new Zend_Config_Ini($file);
  $config = $config->toArray();

        // Create our Application instance (replace this with your appId and secret).
        $facebook = new Facebook(array(
          'appId'  => $config['facebook']['appId'],
          'secret' => $config['facebook']['secret'],
          'cookie' => true,
        ));

        $options = Array(
            'access_token' => $config['facebook']['pageAccessToken'],
            'link' => $request->getPost('link'),
            'picture' => '@' . $request->getPost('picture'),
            'name' => $request->getPost('name'),
            'caption' => $request->getPost('caption'),
            'description' => $request->getPost('description'),
        );
        //Zend_Debug::dump($options); die();
        $wallPost = $facebook->api('/me/feed', 'post', $options);

        $return = 'SUCCESS';
    }

    echo $return;
}

除图像外,一切都按预期工作。知道为什么吗?

【问题讨论】:

标签: php image facebook api post


【解决方案1】:

正如 Brent 和 akond 所提到的,图片链接不应以“@”为前缀,它应该是指向(可能是缩略图大小的)图像的简单 URL。例如,此 curl 命令有效:

set +H  # first turn off history expansion
curl -F \
     "picture=http://tycho.usno.navy.mil/gif/moons/m146.gif" \
     -F "message=you're looking great tonight!" \
     -F "name=Current Moon Phase" \
     -F "link=http://www.calculatorcat.com/moon_phases/phasenow.php" -F caption="How the moon appears tonight" \
     -F "access_token=111111111111111|2222222222222222222222222|33333333333333333333456n" \
     "https://graph.facebook.com/215958041750734/feed"

你可以在https://www.facebook.com/home.php#!/pages/The-Moon/215958041750734看到结果

更新:在@mlunoe 指出感叹号是由 Bash 历史扩展器插入之后,我不知道没有 set +H 的情况下上述内容如何工作。我用单引号测试,没有解决问题,于是在https://unix.stackexchange.com/questions/33339/cant-use-exclamation-mark-in-bash找到了set的解决方案

【讨论】:

  • 不过,有一件事.. 感叹号确实造成了一些麻烦。如果,您将使用它和换行符,例如你应该使用单引号 (') :)
  • 嗯,有一段时间没试过这个了,也许有什么改变了。或者您可能正在使用 Bash 以外的 shell?
  • 不,使用 bash,但 bash 不喜欢双引号中的感叹号。参考:superuser.com/a/133788
  • 好的,我会编辑我的答案。我想我没有遇到问题,因为我在 Makefile 中使用了上述内容?
  • 嘿!是的,很可能就是这样。
猜你喜欢
  • 2011-07-05
  • 2011-07-07
  • 2012-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多