我需要发布到用户的Facebook Feed。
基于其他几个SO问题,我提出了以下发布请求:
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_actions
或manage_pages
和publish_pages
权限。基于这个SO question,这看起来很简单,我最终用这个包装代码进行发布:
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
分支。这里发生了什么?我没有被取消,也没有被要求授予我在Feed上发布任何内容的权限。
PS:我尝试先退出(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>
在这种情况下,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"
,为什么这还不够?
答案 0 :(得分:1)
https://developers.facebook.com/docs/graph-api/changelog/breaking-changes#4-24-2018
已删除publish_actions权限。
由于他们没有提及任何替代方案,因此无法再发布到用户Feed。