facebook graph api - 发布大图

时间:2012-07-16 20:54:57

标签: php facebook facebook-graph-api

我终于让facebooks graph api在我的粉丝PAGE上发布消息page
如何将大图像作为帖子发布,而不是作为链接?
'source' => $photo似乎创建了缩略图

这是我到目前为止所拥有的

<?php

$page_id = 'YOUR-PAGE-ID';
$message = "I'm a Page!";
$photo = "http://www.urlToMyImage.com/pic.jpg";

require '../src/facebook.php';

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
    'appId'  => 'YOUR-APP-ID',
    'secret' => 'YOUR-SECRET-ID',
));


$user = $facebook->getUser();

if ($user) {
    try {
        $page_info = $facebook->api("/$page_id/?fields=access_token");
        if( !empty($page_info['access_token']) ) {
                $facebook->setFileUploadSupport(true); // very important
                $args = array(
                        'access_token'  => $page_info['access_token'],
                        'message'       => $message,
                        'source'        => $photo

                );
                $post_id = $facebook->api("/$page_id/feed","post",$args);
        }
    } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
}

// Login or logout url will be needed depending on current user state.
if ($user) {
    $logoutUrl = $facebook->getLogoutUrl(array( 'next' => 'http://mydomain.com/logout_page.php' ));
} else {
    $loginUrl = $facebook->getLoginUrl(array('scope'=>'manage_pages,publish_stream'));
}
?>

1 个答案:

答案 0 :(得分:1)

这里的问题是你实际上没有张贴照片。您正在做的是发布该照片的链接,因此您看到的确实是Facebook从该网址检索到的缩略图预览图像。

您要做的是提供服务器上带有@符号前缀的文件的完整路径。该主题已经在网站上进行了相当多的讨论,所以我只想指出一个关于使用PHP SDK将图像上传到Facebook的规范帖子的方向

Upload Photo To Album with Facebook's Graph API

代码看起来像这样 -

$facebook->setFileUploadSupport(true);
$params = array('message' => 'Photo Message');
$params['image'] = '@' . realpath($FILE_PATH);
$data = $facebook->api('/me/photos', 'post', $params);