2010-12-22 107 views
2

我無法發佈到Facebook牆壁的鏈接。這樣做的工作就像它應該,只有我試圖附加到它的圖像不會顯示在頁面上。將圖片發佈到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; 
} 

除了圖像以外,一切都按預期工作。任何想法爲什麼請?

+0

爲什麼你有一個@在圖片的URL前?選項圖片參數應該只是一個普通的圖片url,在它前面沒有@。 – 2010-12-22 15:04:09

+0

不,我知道......但這是我在網上找到的一個測試:-) – koko 2010-12-22 20:59:27

回答

2

作爲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

更新看到的結果是:我不知道怎麼沒有set +H上述工作的,之後@mlunoe指出,感嘆號點由Bash歷史擴展器插值。我用單引號測試,並沒有解決問題,所以找到set解決方案https://unix.stackexchange.com/questions/33339/cant-use-exclamation-mark-in-bash