通过Graph API将图像上传到Facebook Wall / Feed [英] Upload image to Facebook Wall / Feed via Graph API

查看:139
本文介绍了通过Graph API将图像上传到Facebook Wall / Feed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将本地图片直接上传到一个网页供稿(即墙壁照片专辑)。

I am trying to upload local images directly to a pages feed (i.e. "Wall Photos" album).

这是我认为应该工作:

This is the code that I think should work:

<?php
$facebook = new Facebook(array(
    'appId'  => $the_app_id,
    'secret' => $this_app_secret,
));
$facebook->setAccessToken($the_access_token);
$facebook->setFileUploadSupport(true);

$attachment = array(
    'message' => $the_post_body,
    'name' => $this_image_name,
    'picture' => '@' . $the_absolute_path_to_image
);

$result = $facebook->api('/me/feed, 'post', $attachment);

但是这个代码只是产生一个带有消息内容的纯文本墙贴(即图片字段似乎被忽略)。我也尝试过/ page_id / feed,结果相同。

But this code just yields a plain text wall post with the contents of "message" (i.e. picture field is seemingly ignored). I have also tried "/page_id/feed", same result.

现在,只需将端点更改为/ me / photos即可将照片上传到正常的专辑,但我希望它看起来像一个普通的帖子尽可能的,所以进入墙壁照片相册)。

Now, simply changing the endpoint to "/me/photos", does upload the photo to a 'normal' album with the name of the app, but I want it to look as much like a normal post as possible and so hence into the "Wall Photos" album).

我意识到我可以通过使用FQL查询图来找到Wall Photos相册的object_id来实现这一点,但是如果不存在,则需要额外的权限来创建它,我宁愿保持尽可能简单的权限

I realise that I could achieve this by querying the graph with FQL to find the object_id of the "Wall Photos" album, but if it does not exist it would require extra permissions to create it and I would rather keep permissions as simple as possible.

如果有人可以指出如何将照片上传到/ me / feed,我将非常感谢。

推荐答案


但是这个代码只是产生一个纯文本墙贴,内容是
message(ie图片字段似乎被忽略)。我也试过
/ page_id / feed,结果相同。

But this code just yields a plain text wall post with the contents of "message" (i.e. picture field is seemingly ignored). I have also tried "/page_id/feed", same result.

你只能给图片链接不是数据。

You can only give the link to picture but not the data.


现在,只需将端点更改为/ me / photos,就将
照片上传到普通专辑与应用程序的名称,但我希望它
看起来像一个正常的帖子尽可能,所以因此进入
墙壁照片相册)。

Now, simply changing the endpoint to "/me/photos", does upload the photo to a 'normal' album with the name of the app, but I want it to look as much like a normal post as possible and so hence into the "Wall Photos" album).

Ye,它根据应用默认创建一个相册。如果已经存在,则会上传到相册。并生成一个帖子。

Ye, it creates an album by default based on app. if already exists, it uploads to album. And generates a post.


我意识到我可以通过使用FQL查询图形
来实现这一点。找到Wall Photos专辑,但如果没有
存在,则需要额外的权限才能创建它,我将
保留尽可能简单的权限。

I realise that I could achieve this by querying the graph with FQL to find the object_id of the "Wall Photos" album, but if it does not exist it would require extra permissions to create it and I would rather keep permissions as simple as possible.

您无法上传到fb / feed终点。您应该存储在您的服务器/ s3 /某些服务中,并将公开的URL发送给我/ feed参数。

You cannot upload to fb for me/feed end point. You should store in your server/s3/some service and give the public url to me/feed params.

这篇关于通过Graph API将图像上传到Facebook Wall / Feed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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