问题
I need to post to user's facebook feed.
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)
}
}
})
This fails due to
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;
};
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)
}
}
})
}
}
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.: 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"
.
The AccessToken.current.grantedPermissions
in that case contains:
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")])
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?
回答1:
https://developers.facebook.com/docs/graph-api/changelog/breaking-changes#4-24-2018
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.
来源:https://stackoverflow.com/questions/50172571/how-to-post-to-users-facebook-feed