如何使用Graph Api v2.2将照片上传到页面

时间:2015-02-03 19:05:59

标签: php facebook facebook-graph-api

之前我曾经创建了几个应用程序,但是现在使用v4我无法将简单的照片上传工作:(我尝试使用'url'并使用'source'参数,但没有任何效果。我想用一些标题将照片上传到我自己的Facebook页面。我获得了访问令牌,访问令牌调试器说,它永远不会过期,它有public_profile,read_stream,read_insights,manage_pages,publish_actions,user_photos权限。

我的代码现在:

$accessToken = "MY-ACCESS-TOKEN";

$session = new FacebookSession($accessToken);

$myfile = "file.png"; //created and saved via PHP GD functions

    if ( isset( $session ) ) {

        try {

            $message = "This is my message";

            $request = new FacebookRequest(
            $session,
            'POST',
            '/'.$pageid.'/photos',
            array (
                'source'        => realpath("/path/to/" . $myfile),
                'message'       => $message,
                )
            );
        } catch (FacebookRequestException $e) {
            echo "Exception occured, code: " . $e->getCode();
            echo " with message: " . $e->getMessage();
        } catch (\Exception $e) {
            echo "Exception occured, code: " . $e->getCode();
            echo " with message: " . $e->getMessage();
        }

        $response = $request->execute();
        $graphObject = $response->getGraphObject();

        /* handle the result */
    } else {
        // show login url
        echo '<a href="' . $helper->getLoginUrl() . '">Login</a>';
    }

现在我收到此错误:

mod_fcgid: stderr: PHP Fatal error:  Uncaught exception 'Facebook\\FacebookAuthorizationException' with message '(#324) Requires upload file' in /data/domains/

我做错了什么?有谁可以帮助我吗?

非常感谢!

0 个答案:

没有答案