开发者

Post a picture to a facebook wall

I have t function to post a link to a Facebook-wall. This works like it should, only the image I try to attach to it doesn't show up on the page.

Do I have to do something special to post an image?

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

    $request = $this->getRequest();
    $this->_helper->getHelper('viewRenderer')->setNoRender();
    $this->_help开发者_开发知识库er->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;
}

Everything works as expected except the image. Any idea why please?


as Brent and akond mentioned, the picture link should not be prefixed by '@', it should be a simple URL to a (presumably thumbnail-sized) image. This curl command, for example, works:

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"

you can see the result at https://www.facebook.com/home.php#!/pages/The-Moon/215958041750734

update: I don't know how the above worked without the set +H, after @mlunoe pointed out that the exclamation point is interpolated by the Bash history expander. I tested with single quotes and didn't solve the problem, so found the set solution at https://unix.stackexchange.com/questions/33339/cant-use-exclamation-mark-in-bash

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜