[GH-ISSUE #464] Post Facebook Feed after login #301

Closed
opened 2026-03-03 16:47:32 +03:00 by kerem · 0 comments
Owner

Originally created by @saroar on GitHub (May 18, 2018).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/464

Description:

i like to post feed to facebook after login is it possible ? if yes how
here how i doing login and trying to post feed

OAuth Provider? (Twitter, Github, ..):

how i login

        let service = "Facebook"

        guard var parameters = services[service] else {
            print("\(service) not configured")
            return
        }

        let oauthswift = OAuth2Swift(
            consumerKey:    parameters["consumerKey"] ?? "",
            consumerSecret: parameters["consumerSecret"] ?? "",
            authorizeUrl:   "https://www.facebook.com/dialog/oauth",
            accessTokenUrl: "https://graph.facebook.com/oauth/access_token",
            responseType:   "code"
        )

        self.oauthswift = oauthswift
        oauthswift.authorizeURLHandler = getURLHandler()
        let state = generateState(withLength: 20)
        _ = oauthswift.authorize(
            withCallbackURL:
            URL(string: "\(PerfectLocalAuth.host)/api/v1/oauth/return/facebook")!,
            scope: "public_profile, email, user_friends",
            state: state,
            success: { credential, response, parameters in

                // send upgrade user signal to Perfect OAuth2 Server
                PerfectLocalAuth.upgradeUser("facebook", credential.oauthToken, { userid in
                    
                    PerfectLocalAuth.userid = userid
                    
                    PerfectLocalAuth.accountType = "facebook"
                    let updateProfilePicUrl = "\(PerfectLocalAuth.host)/api/v1/updateProfileAvator/\(userid)"
                    
                    self.getProfileFacebook(oauthswift, success: { data in
                        
                        let picUrl   = data["picture"]["data"]["url"].stringValue
                        let location = data["location"]["name"].stringValue
                        let params   = ["picture": picUrl, "location": location] as [String: Any]
                        
                        NetworkignService.shared.postRequest(params: params, route: updateProfilePicUrl, completion: { _ in })

                        PerfectLocalAuth.userdetails["location"] = location
                        PerfectLocalAuth.userdetails["picture"] = picUrl
                        
                        DispatchQueue.main.async {
                            self.performSegue(withIdentifier: "welcome", sender: self)
                        }
                    })
                    
//                    self.getFriendsProfileFacebook(oauthswift, success: {  })
                })

        }, failure: { error in
            print("FB login fail:", error.localizedDescription, terminator: "")
        })
    }```

# how i trying to post feed to fb
let services = Services()
@IBAction func shareHeventToFBTapped(_ sender: UISwitch) {
    let service = "Facebook"
    guard var parameters = services[service] else {
        print("\(service) not configured")
        return
    }
    
    let oauthswift = OAuth2Swift(
        consumerKey:    parameters["consumerKey"] ?? "",
        consumerSecret: parameters["consumerSecret"] ?? "",
        authorizeUrl:   "https://www.facebook.com/dialog/oauth",
        accessTokenUrl: "https://graph.facebook.com/oauth/access_token",
        responseType:   "code"
    )
    
    if fbSwitchButton.isOn {
        print("shareHeventToFBTapped button on")
        share = true
        fbTextLabel.textColor = UIColor.white
        fbTextLabel.backgroundColor = UIColor.blue
        print("share", share)
        
        self.sharePost(oauthswift) { json in
            print(json)
        }
    } else {
        share = false
        fbTextLabel.textColor = UIColor.black
        fbTextLabel.backgroundColor = UIColor.lightGray
        print("share", share)
    }
}

func sharePost(_ oauthswift: OAuth2Swift, success: @escaping (JSON) -> Void ) {
    _ = oauthswift.client.post("https://graph.facebook.com/me/feed",
                               parameters: ["message": "This is test message from Adda"],
                               headers: ["Accept": "application/json", "Content-Type":"application/json"],
                               body: nil, success: { response in
        print(response)
    }, failure: { (error) in
        print(error.localizedDescription)
    })
}




Facebook 

### OAuth Version:
using Version 2

### OS (Please fill the version) :
- [x] iOS :

### Installation method:
- [x] iOS CocoaPods

### Library version:
 pod 'OAuthSwift', '~> 1.2.0'

### Xcode version:
- [x] 9.3 (Swift 4.1)
Originally created by @saroar on GitHub (May 18, 2018). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/464 ### Description: i like to post feed to facebook after login is it possible ? if yes how here how i doing login and trying to post feed ### OAuth Provider? (Twitter, Github, ..): how i login ```@IBAction func doFacebookOAuth(_ sender: Any) { let service = "Facebook" guard var parameters = services[service] else { print("\(service) not configured") return } let oauthswift = OAuth2Swift( consumerKey: parameters["consumerKey"] ?? "", consumerSecret: parameters["consumerSecret"] ?? "", authorizeUrl: "https://www.facebook.com/dialog/oauth", accessTokenUrl: "https://graph.facebook.com/oauth/access_token", responseType: "code" ) self.oauthswift = oauthswift oauthswift.authorizeURLHandler = getURLHandler() let state = generateState(withLength: 20) _ = oauthswift.authorize( withCallbackURL: URL(string: "\(PerfectLocalAuth.host)/api/v1/oauth/return/facebook")!, scope: "public_profile, email, user_friends", state: state, success: { credential, response, parameters in // send upgrade user signal to Perfect OAuth2 Server PerfectLocalAuth.upgradeUser("facebook", credential.oauthToken, { userid in PerfectLocalAuth.userid = userid PerfectLocalAuth.accountType = "facebook" let updateProfilePicUrl = "\(PerfectLocalAuth.host)/api/v1/updateProfileAvator/\(userid)" self.getProfileFacebook(oauthswift, success: { data in let picUrl = data["picture"]["data"]["url"].stringValue let location = data["location"]["name"].stringValue let params = ["picture": picUrl, "location": location] as [String: Any] NetworkignService.shared.postRequest(params: params, route: updateProfilePicUrl, completion: { _ in }) PerfectLocalAuth.userdetails["location"] = location PerfectLocalAuth.userdetails["picture"] = picUrl DispatchQueue.main.async { self.performSegue(withIdentifier: "welcome", sender: self) } }) // self.getFriendsProfileFacebook(oauthswift, success: { }) }) }, failure: { error in print("FB login fail:", error.localizedDescription, terminator: "") }) }``` # how i trying to post feed to fb ``` let services = Services() @IBAction func shareHeventToFBTapped(_ sender: UISwitch) { let service = "Facebook" guard var parameters = services[service] else { print("\(service) not configured") return } let oauthswift = OAuth2Swift( consumerKey: parameters["consumerKey"] ?? "", consumerSecret: parameters["consumerSecret"] ?? "", authorizeUrl: "https://www.facebook.com/dialog/oauth", accessTokenUrl: "https://graph.facebook.com/oauth/access_token", responseType: "code" ) if fbSwitchButton.isOn { print("shareHeventToFBTapped button on") share = true fbTextLabel.textColor = UIColor.white fbTextLabel.backgroundColor = UIColor.blue print("share", share) self.sharePost(oauthswift) { json in print(json) } } else { share = false fbTextLabel.textColor = UIColor.black fbTextLabel.backgroundColor = UIColor.lightGray print("share", share) } } -------------------------------------------------------------------- func sharePost(_ oauthswift: OAuth2Swift, success: @escaping (JSON) -> Void ) { _ = oauthswift.client.post("https://graph.facebook.com/me/feed", parameters: ["message": "This is test message from Adda"], headers: ["Accept": "application/json", "Content-Type":"application/json"], body: nil, success: { response in print(response) }, failure: { (error) in print(error.localizedDescription) }) } ``` Facebook ### OAuth Version: using Version 2 ### OS (Please fill the version) : - [x] iOS : ### Installation method: - [x] iOS CocoaPods ### Library version: pod 'OAuthSwift', '~> 1.2.0' ### Xcode version: - [x] 9.3 (Swift 4.1)
kerem closed this issue 2026-03-03 16:47:32 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#301
No description provided.