简体   繁体   中英

How can I request Facebook publish_actions permission wfrom my Swift app?

In my application I'm sending photo to my backend code. I also want to publish this photo to user's facebook wall. User is logged in into my app with FB account already, but I did not yet request his publish_actions permission.

In my application user has a UISwitch that - when turned on - should check if user granted the publish_actions permission, and if he didn't yet - request it from the user.

This is my code so far:

if !(FBSDKAccessToken.current().hasGranted("publish_actions")) {

    print("Request publish_actions permissions")
    let login: FBSDKLoginManager = FBSDKLoginManager()

    login.logIn(withPublishPermissions: ["publish_actions"], from: self) { (result, error) in
        if (error != nil) {
            print(error!)
        } else if (result?.isCancelled)! {
            print("Canceled")
        } else if (result?.grantedPermissions.contains("publish_actions"))! {
            print("permissions granted")

        }
    }
}else {

}

The problem is that when user taps the UISwitch, it opens Safari immediately to ask him about login to Facebook. When he does log in again, there's a message "You have already authorized <>". When user clicks OK , he goes back to the app and in the console I see Canceled .

This doesn't seem right to me, so my question is - what's the best way of asking user to allow for this permission?

Some facebook features need you to send your app for review by facebook before they can be used. You are trying to gain "publish_actions" permission with your own facebook account before you have sent your facebook app for review. In development mode create a test account from developers.facebook.com to test these features.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM