php 使用图形 api 将带有图片的消息发布到 Facebook 页面/提要

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25579835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:54:13  来源:igfitidea点击:

Post message with picture to facebook page/feed using graph api

phpfacebookfacebook-graph-apifacebook-php-sdk

提问by Vladimir Mikhaylovskiy

I'm trying post an a message with one image via facebook graph API, and I can't. In new documentation https://developers.facebook.com/docs/graph-api/reference/v2.1/user/feedthere is no field for an image.

我正在尝试通过 facebook 图形 API 发布一条带有一张图片的消息,但我不能。在新文档https://developers.facebook.com/docs/graph-api/reference/v2.1/user/feed 中,没有图像字段。

If I try to use a field "object_attachment", only small thumbnail appears and post is styling like a share link.

如果我尝试使用“object_attachment”字段,则只会出现小缩略图,并且帖子的样式类似于共享链接。

If I try to use a field "picture", and use url of photo in the internet there is the same result. I can't post "picture" from local,as here:

如果我尝试使用“图片”字段,并在互联网上使用照片的网址,则结果相同。我无法从本地发布“图片”,如下所示:

$post['picture'] = '@' . realpath($image);

error appears: "picture URL is not properly formatted".

出现错误:“图片 URL 格式不正确”。

I just used a free web app to make a post with a photo, and result is just right(see attached image)

我刚用一个免费的网络应用程序用照片发帖,结果恰到好处(见附图)

Please tell me, how can I make a post with the exact result?

请告诉我,我怎样才能发布具有确切结果的帖子?

enter image description here

在此处输入图片说明

采纳答案by Axel Amthor

if you want to post a photo to FB (i.e. in to the Albums) and a text and publish both on the timeline, you need to upload the photo to FB. Not as an attachment with an external URL, but as binary data send to FB.

如果您想将照片发布到 FB(即在相册中)和文本并在时间轴上发布,您需要将照片上传到 FB。不是作为带有外部 URL 的附件,而是作为发送到 FB 的二进制数据。

Have a look at

看一下

     https://graph.facebook.com/<user id>/photos

and within that field source

并在该领域内 source

回答by Atul Jindal

If you need to post post images with the message you have to provide the link of the URL where the image is available.

如果您需要发布带有消息的图片,您必须提供图片可用的 URL 链接。

For reference you can check this link on Facebook documentation,

作为参考,您可以在 Facebook 文档中查看此链接,

https://developers.facebook.com/docs/graph-api/reference/v2.1/user/feed#publish

https://developers.facebook.com/docs/graph-api/reference/v2.1/user/feed#publish

As you told you have not seen any parameter for image, click on link parameter to see further. This will clear your doubt because for posting image, with text, or link you have to use this API.

正如您所说,您还没有看到任何图像参数,请单击链接参数以进一步查看。这将消除您的疑虑,因为要发布图像、文本或链接,您必须使用此 API。

If you want to publish only image then this API will work.

如果您只想发布图像,则此 API 将起作用。

https://developers.facebook.com/docs/graph-api/reference/v2.1/user/picture

https://developers.facebook.com/docs/graph-api/reference/v2.1/user/picture

updated link:

更新链接:

https://developers.facebook.com/docs/graph-api/reference/v2.12/post

https://developers.facebook.com/docs/graph-api/reference/v2.12/post