Skip to content
Reactive extensions for Facebook Login and Graph Request
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Carthage/Checkouts
Example
RxFacebook
.gitignore
.swift-version
.travis.yml
Cartfile
Cartfile.resolved
LICENSE
README.md
RxFacebook.podspec
_Pods.xcodeproj

README.md

Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

import FacebookLogin
import FacebookCore

class Example {
	let loginManager = LoginManager()

	func signIn() {
			loginManager.rx.logIn(with: [.publicProfile]).flatMap { [weak self] (loginResult) -> Observable<EmailResult> in
							guard let strongSelf = self else { return .just((nil, "Something went wrong")) }
							switch loginResult {
							case .cancelled: return .just((nil, "User cancelled the result"))
							case let .failed(error): return .just((nil, error.localizedDescription))
							// Extract the facebook login result here and chain it with your graph request
							case let .success(acceptedPermissions, declinedPermissions, accessToken): return strongSelf.fetchEmail()
							}
					}
					.subscribe(onNext: { email, error in
							if let `email` = email {
									print(email)
							} else if let `error` = error {
									print(error)
							}
					})
					.disposed(by: disposeBag)
	}

	func fetchEmail() -> Observable<EmailResult> {
			let graphRequest  = GraphRequest(graphPath: "/me")
			return graphRequest.rx.getResponse().map { result in
					switch result {
					case let .success(response):
							guard let objectMap = response.dictionaryValue, let email = objectMap["email"] as? String else { return (nil, "Couldn't find email") }
							return (email, nil)
					case let .failed(error):
							return (nil, error.localizedDescription)
					}
			}
	}
}

Requirements

pod 'RxSwift'
pod 'FacebookCore'
pod 'FacebookLogin'

Installation

RxFacebook is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'RxFacebook'

Author

Sourav Chandra RxSwift Enthusiast saurav.chandra1992@live.com

License

RxFacebook is available under the MIT license. See the LICENSE file for more info.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.