通过 Graph iOS SDK 将视频分享到 Facebook

发布于 2025-01-13 13:09:56 字数 2183 浏览 2 评论 0原文

我尝试使用 Graph API 将视频上传到 Facebook。 但总是看到错误信息

(#100) 无权发布视频。

Facebook 应用程序有开发模式。我在那里创建了测试用户。我的角色是管理员。 FB 访问令牌有效。

这是我的代码:

private func upload(url: URL) {
        guard let data = try? Data(contentsOf: url) else { return }
        let connection = GraphRequestConnection()
        connection.delegate = self
        var items: [String: Any] = [:]
        items["title"] = "Test title from api"
        items["\(url.absoluteString)"] = data
        let keys = ["value" : "EVERYONE"]
        items["privacy"] = keys
        
        let request = GraphRequest(graphPath:  "me/videos", parameters: items, httpMethod: .post)
        
        connection.add(request) { reqconnection, anyInfo, error in
            print(reqconnection)
            print(anyInfo)
            print(error)
        }
        
        connection.start()
    }

我看到了很多关于它的问题,但大多数都太旧了,不适合我。

  1. 将视频分享到 FB
  2. 来自线程 FB 开发者 这里 - 同样的错误,但他们没有找到解决方案
  3. 还要检查这个docs - 不起作用

而且我有点困惑什么文档适合在 Facebook 上发布视频。 因为在文档中我看到

视频 API 允许您在页面和群组上发布视频。不支持在用户上发布。

但也在另一个文档中看到带有路径 me/videos 的 Graph API。所以这让我有点困惑。

哪些文档适合我的情况:

  1. 此处
  2. 此处

从文档中我看到

您的应用应按如下方式管理权限: Graph API 请求 - 在发送 Graph API 请求之前,您应该检查必要的权限并在需要时请求它们。

在哪里可以找到publish_actions权限?

请帮忙弄清楚如何解决这个问题。

我只能通过 ShareDialog 上传。就像此处和文档此处

I try to upload video to Facebook using Graph API.
But always see error message

(#100) No permission to publish the video.

Facebook app has Development mode. I created test user there. My role is admin. FB access token is valid.

Here my code here:

private func upload(url: URL) {
        guard let data = try? Data(contentsOf: url) else { return }
        let connection = GraphRequestConnection()
        connection.delegate = self
        var items: [String: Any] = [:]
        items["title"] = "Test title from api"
        items["\(url.absoluteString)"] = data
        let keys = ["value" : "EVERYONE"]
        items["privacy"] = keys
        
        let request = GraphRequest(graphPath:  "me/videos", parameters: items, httpMethod: .post)
        
        connection.add(request) { reqconnection, anyInfo, error in
            print(reqconnection)
            print(anyInfo)
            print(error)
        }
        
        connection.start()
    }

I saw a lot of questions about it, but mostly they are too old and don't work for me.

  1. Share video to FB
  2. From thread FB Developers here - the same error, but they didn't find solution
  3. Also check this docs - doesn't work

Also I'm a bit confused what docs are right for post video in Facebook.
Because in docs I see

The Video API allows you to publish Videos on Pages and Groups. Publishing on Users is not supported.

but also in another docs see Graph API with path me/videos. So it confused me a bit.

What docs are correct for my case:

  1. here
  2. here

From docs I see that

Your app should manage permissions as follows:
Graph API Requests - Before you send Graph API requests, you should check for necessary permissions and request them if needed.

Where can I find permission publish_actions?

Please help to figure out how to fix that.

I only can upload via ShareDialog. Like here and docs here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文