Post to FB page using iOS SDK fails while Graph API Explorer works

Viewed 100

still struggling with this d*** FB SDK :-/

Basically, I've got an app that is supposed to post content to a FB Page. To achieve that, I login using the FB sdk. Then I request authorisations as follow

LoginManager().logIn(permissions: ["pages_manage_posts", "pages_read_engagement", "pages_show_list"], viewController: controller) { result in
                    print("res \(result)")
                    switch result {
                    case .success:
                        // the pageId is in data>id
                        Defaults[\.facebookSwitchOn] = true
                        GraphRequest.init(graphPath: "me/accounts").start { (connexion, result, error) in
                            guard let result = result as? [String:Any],
                                  let dataArray = result["data"] as? Array<Any>,
                                  let data = dataArray.first as? [String:Any],
                                  let pageId = data["id"] as? String,
                                  let access = data["access_token"] as? String else { return }
                            print("\(pageId)")
                            Defaults[\.facebookPageId] = pageId
                            Defaults[\.facebookPageAccessToken] = access
                        }
                        completion(true)

                    case .failed(let error):
                        completion(false)
                        MessageManager.show(.basic(.custom(title: "Oups".local(), message: error.localizedDescription, buttonTitle: nil, configuration: MessageDisplayConfiguration.alert)), in: controller)

                    default: ()
                    }
                }

I save the pageId and TokenID to be able to perform a POST request as follow

GraphRequest
                    .init(graphPath: "\(pageId)/photos",
//                    parameters: ["source" : image, "caption" : text, "access_token" : token, "published" : false],
                        parameters: ["caption" : contentDescription, "url" : "https://www.cdiscount.com/pdt2/9/2/8/1/700x700/889698377928/rw/figurine-funko-pop-deluxe-game-of-thrones-daen.jpg", "access_token" : token],
                        httpMethod: .post)
                    .start { (connexion, result, error) in
                    completion(Result.success(true))
                }

However, I get a weird error telling that publish_actions has been deprecated. I logged the request using Charles, and here it is https://ibb.co/89wPgKx. Now here is the debug from the GraphAPI explorer :

curl -i -X POST \ "https://graph.facebook.com/v7.0/104226051340555/photos?caption=test%20message%20from%20Graph%20API%20for%20photo&url=https%3A%2F%2Fwww.cdiscount.com%2Fpdt2%2F9%2F2%2F8%2F1%2F700x700%2F889698377928%2Frw%2Ffigurine-funko-pop-deluxe-game-of-thrones-daen.jpg&access_token=<access token sanitized>"

Basically, it is the same request excepting the fact that parameters in the explorer are URL parameters and they are encapsulated in a json.

I can't understand why the graph explorer request succeeds while the SDK request fails. I'm totally stuck :-/

Thanks for your help.

0 Answers
Related