2

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->_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;
}

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

koenHuybrechts
  • 868
  • 4
  • 15
  • 28
  • Why do you have an @ in front of the picture URL? The options picture parameter should just be a plain image url, no @ in front of it. – Brent Baisley Dec 22 '10 at 15:04
  • No, I know ... but it was a test I did find online :-) – koenHuybrechts Dec 22 '10 at 20:59
  • As http://developers.facebook.com/docs/reference/api/post/ states, the `picture` parameter must contain "a link to the picture included with this post", i.e. something like http://www.example.com/article-thumbnail.jpg. What do you provide? – akond May 19 '11 at 11:40

1 Answers1

2

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

Community
  • 1
  • 1
jcomeau_ictx
  • 37,688
  • 6
  • 92
  • 107
  • One thing, though.. The exclamation mark did cause some trouble. If, you're going to use that and newline e.g. you should use single quotes (`'`) :) – mlunoe Jun 19 '13 at 23:06
  • hmm, haven't tried this for a while, maybe something changed. or perhaps you're using a shell other than Bash? – jcomeau_ictx Jun 19 '13 at 23:19
  • Nope, using bash, but bash don't like the exclamation marks in the double quotes. Reference: http://superuser.com/a/133788 – mlunoe Jun 19 '13 at 23:58
  • okay, I'll edit my answer. I guess I didn't run into the problem because I used the above in a Makefile? – jcomeau_ictx Jun 20 '13 at 00:02
  • Heh! Yeah, that may very well have been the case. – mlunoe Jun 20 '13 at 00:03
  • ugh. testing with single-quotes still fails. – jcomeau_ictx Jun 20 '13 at 00:09
  • Instead of `set +H`, you could use the double quotes `"` in combination with single quotes `'` as pointed out here: http://stackoverflow.com/a/1250279/1008519. So the line would look something like this: `-F 'message=you'"'"'re looking great tonight!' \` – mlunoe Jun 20 '13 at 08:15