将图片张贴到Facebook墙上 [英] Post a picture to a facebook wall
问题描述
我必须做一些特殊的事情来发布图像?
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。 '模块'。 DS。 社会。 DS。 'config'。 DS。 的config.ini;
$ config = new Zend_Config_Ini($ file);
$ config = $ config-> toArray();
//创建我们的应用程序实例(将其替换为您的appId和密码)。
$ 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);死();
$ wallPost = $ facebook-> api('/ me / feed','post',$ options);
$ return ='SUCCESS';
}
echo $ return;
}
除图像外,一切都按预期方式运行。任何想法为什么?
作为Brent和akond提到,图片链接不应以'@'为前缀,应该是一个简单的URL(大概是缩略图大小的)图像。例如,这个卷曲命令的作用如下:
set + H#首先关闭历史记录扩展
curl -F \\ \\
picture = http://tycho.usno.navy.mil/gif/moons/m146.gif\
-Fmessage =你今晚看起来很棒! \
-Fname =当前月相\
-Flink = http://www.calculatorcat.com/moon_phases/phasenow.php-F caption =如何月亮今天晚上出现\
-Faccess_token = 111111111111111 | 2222222222222222222222222 | 33333333333333333333456n\
https://graph.facebook.com/215958041750734/feed
您可以在 https://www.facebook.com/home.php#!/pages/The-Moon/215958041750734
更新:在@mlunoe指出感叹号由Bash历史扩展器插值之后,我不知道上述如何没有使用 set + H
。我用单引号测试,没有解决问题,所以在设置解决方案/cant-use-exclamation-mark-in-bash\"> https://unix.stackexchange.com/questions/33339/cant-use-exclamation-mark-in-bash
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?
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
这篇关于将图片张贴到Facebook墙上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!