在 PHP facebook 中创建事件时发送

发布于 2024-10-26 02:13:06 字数 1832 浏览 1 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文