在 PHP facebook 中创建事件时发送
我正在尝试使用 fb Graph API(不是 php-sdk)发布一个新事件 事实上,除了图片之外,一切都很好。 这就是我所做的:
<?php
public function publish($url){
$params = $this->getParameter();
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch,CURLOPT_POSTFIELDS,$params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$returnValue = curl_exec($ch);
curl_close($ch);
return $returnValue;
}
public function getParameter() {
$params["access_token"] = FbAuthentication::getInstance()->getToken();
foreach ($this as $attr => $value) {
if( $value != null)
$params[ $attr ] = $value;
}
//this things is actually done inside an inheriting class (the $picture attr is protected)
if( $this->picture != null){
$real = realpath($this->picture);
if(!file_exists($this->picture))
throw new Exception("File $this->picture not found");
$params[basename($real)]="@$real";
}
return $params;
}
?>
$params 数组没问题(我认为)。这是一个 var_dump():
array(6) {
["access_token"]=>
string(79) "......"
["name"]=>
string(17) "Name example"
["description"]=>
string(16) "Desc example"
["start_time"]=>
string(19) "2011-03-22T18:00:00"
["end_time"]=>
string(19) "2011-03-22T20:00:00"
["logo.gif"]=>
string(26) "@/home/alessandro/logo.gif"
}
如果我不设置“$picture”参数,一切都会正常,但如果我确实放置了图像 我收到此错误:
{"error":
{"type":"OAuthException",
"message":"(#324) Missing or invalid image file"}
}
知道如何修复它吗? 谢谢
编辑:由于某种未知的原因,这个东西适用于 pnj/jpeg 文件。 它没有gif图片...
I'm trying to POST a new event with fb Graph API (not the php-sdk)
actually, everything works fine, except for the picture thing.
Here is what i do:
<?php
public function publish($url){
$params = $this->getParameter();
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch,CURLOPT_POSTFIELDS,$params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$returnValue = curl_exec($ch);
curl_close($ch);
return $returnValue;
}
public function getParameter() {
$params["access_token"] = FbAuthentication::getInstance()->getToken();
foreach ($this as $attr => $value) {
if( $value != null)
$params[ $attr ] = $value;
}
//this things is actually done inside an inheriting class (the $picture attr is protected)
if( $this->picture != null){
$real = realpath($this->picture);
if(!file_exists($this->picture))
throw new Exception("File $this->picture not found");
$params[basename($real)]="@$real";
}
return $params;
}
?>
The $params array is ok (i think). Here's a var_dump():
array(6) {
["access_token"]=>
string(79) "......"
["name"]=>
string(17) "Name example"
["description"]=>
string(16) "Desc example"
["start_time"]=>
string(19) "2011-03-22T18:00:00"
["end_time"]=>
string(19) "2011-03-22T20:00:00"
["logo.gif"]=>
string(26) "@/home/alessandro/logo.gif"
}
If i don't set the "$picture" parameter everything works well, but if I do put the image
I recive this error:
{"error":
{"type":"OAuthException",
"message":"(#324) Missing or invalid image file"}
}
Any idea of how to fix it?
Thanks
Edit: for some unknown reason this things works well with a pnj/jpeg file.
It doesn't with a gif pic...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论