Facebook图形api-发布大图 [英] facebook graph api - post large image

查看:106
本文介绍了Facebook图形api-发布大图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我终于有了facebook graph api,将消息以page
的形式发布到我的粉丝专页上 如何将大图像发布为帖子而不是链接?

'source' => $photo似乎创建了缩略图

I finally got facebooks graph api to post messages on my fan PAGE as page
How do i get it to post large images as a post, not as a link?

'source' => $photo seems to create a thumbnail

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

this is what i have so far

<?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'));
}
?>

推荐答案

这里的问题是您实际上没有发布照片.您正在做的是发布指向该照片的链接,因此您看到的确实是Facebook从该URL检索到的缩略图预览图像.

The problem here is that you are in actual fact not posting a photo. What you are doing is posting a link to that photo so what you see is indeed a thumbnail preview image that Facebook retrieved from that URL.

您要做的是提供服务器上以@符号为前缀的文件的完整路径.该主题已在网站上进行了很多讨论,因此,我只为您指出有关使用PHP SDK将图像上传到Facebook的规范文章的方向.

What you'll want to do is provide a full path to a file on your server prefixed with the @ symbol. The topic has been discussed on the site quite a bit so I'll just point you in the direction of a canonical post dealing with uploading of images to Facebook with the PHP SDK

使用Facebook的Graph API将照片上传到相册

代码看起来像这样-

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

这篇关于Facebook图形api-发布大图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆