【问题标题】:Can't create media using facebook instagram graph api无法使用 facebook instagram graph api 创建媒体
【发布时间】:2021-07-19 09:29:10
【问题描述】:

我有一个测试业务应用程序,我可以在其中正常查询有关用户的信息。 我可以在我的 Facebook 页面上成功验证所需的范围。

这是我要求的范围:instagram_basic,instagram_content_publish,user_events,user_videos,user_posts

但是,当我尝试使用 this api 创建帖子时,出现错误。这是请求:

curl --location --request POST 'https://graph.facebook.com/me/media?access_token={ommited}' \
                --form 'image_url="https://cdn1.vectorstock.com/i/thumbs/59/70/flat-robot-vector-20655970.jpg"' \
                --form 'caption="nothing to see here :-"'

回复:

"error": {
        "message": "Unsupported post request. Object with ID 'me' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api"
}
...

我也尝试了使用 user_id 而不是 me 的请求,但也不起作用。

【问题讨论】:

标签: facebook instagram instagram-graph-api


【解决方案1】:

好吧,我想通了。

基本上,当我们查询/media 端点时,api 需要一个“IG 用户”ID。在这种情况下,我使用的是 FB 用户令牌,因此 API 无法确定“我”是谁。我们只能在拥有access_tokens(即用户和页面)的对象上真正使用“我”。

我通过传递我的 instagram_business_account id 解决了这个问题,可以通过传递以下字段在 FB 用户端点 (https://graph.facebook.com/me/?access_token=user_access_token) 上进行查询:

fields=accounts{instagram_business_account{id}}

这基本上返回与用户关联的帐户(即“页面”)以及与这些页面关联的“IG 用户”。

--

因此,最终实际创建媒体容器的最终请求将如下所示:

# Endpoint
https://graph.facebook.com/*instagram_business_id*/media
# replace instagram_business_id with the instagram_business_id you got upon querying the Graph API
# query params:
    
     - access_token=
     - image_url=https://cdn1.vectorstock.com/i/thumbs/59/70/flat-robot-vector-20655970.jpg
     - caption=your_image_caption

【讨论】:

  • 好吧,也许您可​​以提供帮助...当使用 instagram_business_account 调用 graph.facebook.com/".$instagram_business_account."/… 以及 POST 中的 image_url 和标题时,我没有取回容器 ID...所以您可以编辑您的答案解释你做了什么?
  • @Peter 也许您可以显示您正在尝试执行的请求以及您得到的响应?把它上传到某个地方。
猜你喜欢
  • 2017-08-28
  • 1970-01-01
  • 2018-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-21
  • 1970-01-01
  • 2018-12-06
相关资源
最近更新 更多