在PHP facebook中创建活动时发送

时间:2011-03-25 23:59:08

标签: php facebook-graph-api

我正在尝试使用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图片...

1 个答案:

答案 0 :(得分:1)

阅读这篇文章......

http://www.joeyrivera.com/2010/facebook-graph-api-app-easy-w-php-sdk/

看看评论#43,#44,也许你可以找到任何线索。