如何发布到用户的Facebook提要 [英] How to post to user's facebook feed

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

问题描述

我需要发布到用户的Facebook feed.

I need to post to user's facebook feed.

基于其他几个SO问题,我提出了以下发布请求:

Based on several other SO questions I came up with the following posting request:

let request = GraphRequest(graphPath: "me/feed", parameters: ["message" : "Hello world"], accessToken: accessToken, httpMethod: .POST, apiVersion: GraphAPIVersion.defaultVersion)
request.start({ (response, requestResult) in

    switch requestResult {
    case .failed(let error):
        print("error in graph request:", error)

    case .success(let graphResponse):
        if let responseDictionary = graphResponse.dictionaryValue {
            print(responseDictionary)
        }
    }
})

由于

error =         {
    code = 200;
    "fbtrace_id" = GMp2cebddNb;
    message = "(#200) Requires either publish_actions permission, or manage_pages and publish_pages as an admin with sufficient administrative permission";
    type = OAuthException;
};

根据消息来看,该问题似乎很容易解决-我所需要做的就是获取publish_actionsmanage_pagespublish_pages权限.根据这个 SO问题,这似乎很简单,我最终想到了包装要发布的代码:

Based on the message, the problem seemed to be an easy to solve - all I need is to get either publish_actions, or manage_pages and publish_pages permissions. Based on this SO question, this seemed easy and I ended up in wrapping the code for posting with this:

let loginManager = LoginManager()
loginManager.logIn([PublishPermission.custom("publish_actions")], viewController: self) { (result) in

    print(">> \(AccessToken.current?.grantedPermissions)")

    switch result {

    case .cancelled:
        print(">>>> Cancelled")

    case .failed(let error):
        print(">>>> Error: \(error)" )

    case .success(grantedPermissions: _, declinedPermissions: _, token: let accessToken):
        print(">>>> Logged in!")
        let request = GraphRequest(graphPath: "me/feed", parameters: ["message" : post], accessToken: accessToken, httpMethod: .POST, apiVersion: GraphAPIVersion.defaultVersion)
        request.start({ (response, requestResult) in

            switch requestResult {
            case .failed(let error):
                print("error in graph request:", error)
                break
            case .success(let graphResponse):
                if let responseDictionary = graphResponse.dictionaryValue {
                    print(responseDictionary)
                }
            }
        })
    }
}

现在,有趣"部分是,facebook SDK显示了一个页面,告诉我我以前使用Facebook登录到我的应用程序,并询问我是否要继续.当我按继续时,SafariViewController消失,并且.cancelled分支被执行.这里发生了什么?我尚未取消,也没有被要求授予在我的供稿上发布任何内容的权限.

Now the "funny" part is, that then the facebook SDK shows a page telling me that I previously logged in to my app using Facebook and asks me if I would like to continue. When I press Continue, the SafariViewController dismisses and the .cancelled branch gets executed. What is going on here? I haven't cancelled, nor have I been asked to grant permissions to publish anything on my feed.

P.S .:我尝试先注销(loginManager.logOut()和/或AccessToken.current = nil),在这种情况下,.success分支将执行,但再次出现相同的错误"(#200) Requires either publish_actions permission, or manage_pages and publish_pages as an admin with sufficient administrative permission".

P.S.: I tried logging out first (loginManager.logOut() and/or AccessToken.current = nil), in that case the .success branch executes but again with the same error "(#200) Requires either publish_actions permission, or manage_pages and publish_pages as an admin with sufficient administrative permission".

在这种情况下,AccessToken.current.grantedPermissions包含:

Set([FacebookCore.Permission(name: "user_friends"),
    FacebookCore.Permission(name: "publish_pages"), 
    FacebookCore.Permission(name: "user_location"), 
    FacebookCore.Permission(name: "email"), 
    FacebookCore.Permission(name: "user_likes"), 
    FacebookCore.Permission(name: "pages_show_list"), 
    FacebookCore.Permission(name: "manage_pages"), 
    FacebookCore.Permission(name: "user_photos"), 
    FacebookCore.Permission(name: "public_profile"), 
    FacebookCore.Permission(name: "user_posts"), 
    FacebookCore.Permission(name: "user_birthday")])

因此没有publish_actions权限!为什么在未授予我所要求的许可的情况下成功进行登录?而且,我显然有"manage_pages""publish_pages",那为什么还不够?

So no publish_actions permission! Why does the login go through successfully while not granting me the permission that I ask for? Moreover, I obviously have "manage_pages" and "publish_pages", so why is that not enough?

推荐答案

https://developers.facebook.com/docs/graph-api/changelog/breaking-changes#4-24-2018

publish_actions权限已被删除.

The publish_actions permission has been removed.

由于他们没有提及任何替代方法,因此无法再向用户供稿发布.

Since they do not mention any alternative, there is no way to post to the user feed anymore.

这篇关于如何发布到用户的Facebook提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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