diff --git a/.DS_Store b/.DS_Store
index b176e5f..9e42653 100644
Binary files a/.DS_Store and b/.DS_Store differ
diff --git a/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/UserInterfaceState.xcuserstate b/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/UserInterfaceState.xcuserstate
index c557fa4..34db356 100644
Binary files a/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/UserInterfaceState.xcuserstate and b/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
index 95ed704..7e02f3d 100644
--- a/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
+++ b/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
@@ -10,27 +10,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/FacebookGraphAPIManager.swift"
- timestampString = "486227901.505474"
+ timestampString = "486403080.878544"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "73"
- endingLineNumber = "73"
- landmarkName = "authorizeApp(_:)"
- landmarkType = "5">
-
-
-
-
@@ -38,16 +22,16 @@
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
- symbolName = "Vendoo.FacebookGraphAPIManager.isAuthorized.getter : Swift.Bool"
+ symbolName = "Vendoo.FacebookGraphAPIManager.isAuthorized.setter : Swift.Bool"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/FacebookGraphAPIManager.swift"
- timestampString = "486227901.651867"
+ timestampString = "486426967.061218"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "27"
- endingLineNumber = "27"
- offsetFromSymbolStart = "11">
+ startingLineNumber = "35"
+ endingLineNumber = "35"
+ offsetFromSymbolStart = "27">
+ startingLineNumber = "35"
+ endingLineNumber = "35"
+ offsetFromSymbolStart = "584">
@@ -74,187 +58,187 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/FacebookGraphAPIManager.swift"
- timestampString = "486227622.356175"
- startingColumnNumber = "9223372036854775807"
- endingColumnNumber = "9223372036854775807"
- startingLineNumber = "59"
- endingLineNumber = "59"
- landmarkName = "authorizeApp(_:)"
- landmarkType = "5">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+ startingLineNumber = "149"
+ endingLineNumber = "149"
+ offsetFromSymbolStart = "1020">
+ startingLineNumber = "149"
+ endingLineNumber = "149"
+ offsetFromSymbolStart = "254">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -266,13 +250,77 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/FacebookGraphAPIManager.swift"
- timestampString = "486227898.081641"
+ timestampString = "486407553.29875"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "74"
- endingLineNumber = "74"
+ startingLineNumber = "165"
+ endingLineNumber = "165"
+ landmarkName = "makeDELETIONResquest(_:params:)"
+ landmarkType = "5">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Vendoo/.DS_Store b/Vendoo/.DS_Store
index 2097962..78c56e2 100644
Binary files a/Vendoo/.DS_Store and b/Vendoo/.DS_Store differ
diff --git a/Vendoo/FacebookGraphAPIManager.swift b/Vendoo/FacebookGraphAPIManager.swift
index 19daa7d..8e66d44 100644
--- a/Vendoo/FacebookGraphAPIManager.swift
+++ b/Vendoo/FacebookGraphAPIManager.swift
@@ -12,12 +12,13 @@ import FBSDKCoreKit
import FBSDKLoginKit
import AeroGearHttp
import AeroGearOAuth2
-//import OAuthSwift
+import OAuthSwift
+import Locksmith
/*
NOTES:
- I am able to authorize application for use with facebook but cannot deathorize and completion block of authorization code is not being called -> need to figure this out
+ I am able to authorize application for use with facebook and deauthorize it while showing the toggle button switching back and forth, but during the last step of the process, for some reason NSUserDefault key for fbauthorized is not being called, in response handler, may need to run in a different thread
*/
class FacebookGraphAPIManager: NSObject {
@@ -25,10 +26,12 @@ class FacebookGraphAPIManager: NSObject {
//----------------------------------------------//
static let sharedInstance = FacebookGraphAPIManager()
- let graphBaseURL = "graph.facebook.com"
+ let graphBaseURL = "https://graph.facebook.com/v2.2"
private var apiKey: String!
private var apiSecret: String!
+ private var userEmail:String = (NSUserDefaults.standardUserDefaults().objectForKey("email") as? String)!
+ private let login: FBSDKLoginManager = FBSDKLoginManager()
var isAuthorized: Bool = NSUserDefaults.standardUserDefaults().boolForKey("fbAuthorized")
//---------------------------------------------//
@@ -38,6 +41,14 @@ class FacebookGraphAPIManager: NSObject {
self.apiKey = ((dict["Facebook"] as! Dictionary)["consumerKey"] as! String)
self.apiSecret = ((dict["Facebook"] as! Dictionary)["consumerSecret"] as! String)
+
+ if(isAuthorized){
+
+ let dictionary = Locksmith.loadDataForUserAccount(self.userEmail, inService: "vendoo")
+ print("account credentials loaded")
+ //print((NSUserDefaults.standardUserDefaults().objectForKey("") as? FBSDKAccessToken!))
+ }
+
}
}
@@ -48,64 +59,137 @@ class FacebookGraphAPIManager: NSObject {
//MARK: - OAuth Methods
extension FacebookGraphAPIManager {
- func authorizeApp(viewcontroller: UIViewController){
+ func authorizeApp(viewcontroller: UIViewController) -> Bool{
- let http = Http(baseURL: self.graphBaseURL) // [1]
- let facebookConfig = FacebookConfig( // [2]
- clientId: self.apiKey,
- clientSecret: self.apiSecret,
- scopes:["publish_actions"])
- let oauth2Module = AccountManager.addFacebookAccount(facebookConfig) // [3]
-
-
- http.authzModule = oauth2Module // [4]
-
- //dispatch_async(dispatch_main(), <#T##block: dispatch_block_t##dispatch_block_t##() -> Void#>)
- http.request(.GET, path: "/get", completionHandler: {
- (response, error) in // [5]
- // handle response
-
- //print(response)
- /*if((error != nil)){
+ login.loginBehavior = FBSDKLoginBehavior.Web
+ if(!self.isAuthorized){
+ if(FBSDKAccessToken.currentAccessToken() == nil){
+ var boolResult:Bool = false
+ dispatch_async(dispatch_get_main_queue(), { () -> Void in
+ self.login.logInWithReadPermissions([/*"publish_actions", */"public_profile"], fromViewController: viewcontroller, handler: {
+ (result, error) -> Void in
+
+ if (error != nil) {
+ NSLog("Process error")
+ boolResult = false
+ }
+ else if result.isCancelled {
+ NSLog("Cancelled")
+ boolResult = false
+ }
+ else {
+
+ NSLog("Logged in with read permissions")
+
+ print(result.token)
+ print(result.grantedPermissions)
+ NSUserDefaults.standardUserDefaults().setBool(true, forKey:"fbAuthorized")
+
+ FBSDKAccessToken.setCurrentAccessToken(result.token)
+
+ print("user logged in through facebook")
+ self.makeGETRequest("",params: nil)
+
+ }
+ if(!FBSDKAccessToken.currentAccessToken().hasGranted("publish_actions")){
+ dispatch_async(dispatch_get_main_queue(), { () -> Void in
+
+ self.login.logInWithPublishPermissions(["publish_actions"], fromViewController: nil,handler: {
+ (result, error) -> Void in
+
+ NSLog("Logged in with publish permisions")
+ })
+
+ })
+
+ }
+ })
+ })
- //once everything is authorized save true value to the authorization boolean
-
- NSUserDefaults.standardUserDefaults().setBool(true, forKey: "fbAuthorized")
- self.isAuthorized = NSUserDefaults.standardUserDefaults().boolForKey("fbAuthorized")
-
- }*/
- })
-
- // self.isAuthorized = oauth2Module.isAuthorized()
-
-
- /*
- oauth2Module.revokeAccess({(response, error) in
- if (error != nil) {
- // do something with error
- print("accessrevoked")
+ return boolResult
}
- // do domething
- })
- */
+ print("token not valid")
+ return false
+ }
+ else{
+ print(FBSDKAccessToken.currentAccessToken())
+ print("user already logged in")
+ self.makeGETRequest("",params: nil)
+ return true
+ }
}
- func deAuthorizeApp(viewcontroller: UIViewController){
- let facebookConfig = FacebookConfig( // [2]
- clientId: self.apiKey,
- clientSecret: self.apiSecret,
- scopes:["publish_actions"])
- let oauth2Module = AccountManager.addFacebookAccount(facebookConfig) // [3]
- oauth2Module.revokeAccess({(response, error) in
- if (error != nil) {
- // do something with error
- }
- // do domething
- })
+ func deAuthorizeApp(viewcontroller: UIViewController) -> Bool{
+ return self.makeDELETIONResquest("/permissions", params: nil)
}
}
+
+//MARK: - request methods(GET, POST, DELETE)
+extension FacebookGraphAPIManager {
+
+ //when making request make sure path starts with '/'
+ func makeGETRequest(requestPath: String!, params: [NSObject: AnyObject]!) -> Bool{
+
+ let graphRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me" + requestPath, parameters: params)
+ var boolResult: Bool = false
+
+ graphRequest.startWithCompletionHandler({
+ (id, result, error) -> Void in
+
+ print(result)
+
+
+
+
+ })
+ return boolResult
+
+ }
+
+ //used to post to users timeline, path must start with '/'
+ func makePOSTResquest(requestPath: String!, params: [NSObject: AnyObject]!){
+
+ let graphRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me" + requestPath, parameters: params, HTTPMethod: "POST")
+ graphRequest.startWithCompletionHandler({
+ (id, result, error) -> Void in
+ print(result)
+ })
+ }
+
+ //used to delete permissions and listings from users timeline, path must start with '/'
+ func makeDELETIONResquest(requestPath: String!, params: [NSObject: AnyObject]!) -> Bool{
+
+ let graphRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me" + requestPath, parameters: params, HTTPMethod: "DELETE")
+ var boolResult: Bool = false
+ dispatch_async(dispatch_get_main_queue(), {
+ graphRequest.startWithCompletionHandler({
+ (id, result, error) -> Void in
+ print(result)
+
+ if(requestPath == "/permssions"){
+ if(error == nil){
+ //this part is not getting called but almost have the oauth done
+ boolResult = true
+ NSUserDefaults.standardUserDefaults().setBool(false, forKey:"fbAuthorized")
+ }
+ else{
+ print(error.localizedDescription)
+ boolResult = false
+
+ }
+ }
+
+ boolResult = false
+ })
+ })
+
+
+ return boolResult
+ }
+
+}
diff --git a/Vendoo/Info.plist b/Vendoo/Info.plist
index 32a4817..1fee3a0 100644
--- a/Vendoo/Info.plist
+++ b/Vendoo/Info.plist
@@ -24,7 +24,7 @@
CFBundleTypeRole
Editor
CFBundleURLName
-
+ com.Kroleo.Vendoo
CFBundleURLSchemes
fb504150909777657
@@ -39,8 +39,9 @@
Vendoo
LSApplicationQueriesSchemes
- fbapi
fbauth2
+ fbapi
+ fb-messenger-api
fbshareextension
LSRequiresIPhoneOS
diff --git a/Vendoo/NetworksTableViewController.swift b/Vendoo/NetworksTableViewController.swift
index 20ae9b6..ae93fa1 100644
--- a/Vendoo/NetworksTableViewController.swift
+++ b/Vendoo/NetworksTableViewController.swift
@@ -143,8 +143,13 @@ extension NetworksTableViewController: UITableViewDataSource {
cell = (self.tableView.dequeueReusableCellWithIdentifier("etsy", forIndexPath: indexPath) as! EtsyTableViewCell)
break
default:
- //loads network cell for ebay
+ //loads network cell for facebook
cell = (self.tableView.dequeueReusableCellWithIdentifier("facebook", forIndexPath: indexPath) as! FBTableViewCell)
+
+ if((self.tabBarController as? HomeViewController)?.fbGraphManager.isAuthorized)!{
+
+ (cell as! FBTableViewCell).networkToggle.setOn(true, animated: false)
+ }
break
}
}
@@ -415,15 +420,17 @@ extension NetworksTableViewController: UITableViewDelegate {
cell = (self.tableView.dequeueReusableCellWithIdentifier("facebook", forIndexPath: indexPath) as! FBTableViewCell)
cell.setSelected(false, animated: false)
-
//OAuthorization code for facebook
- if(cell.networkToggle.on == true){
+ if((self.tabBarController as? HomeViewController)?.fbGraphManager.isAuthorized)!{
dispatch_async(dispatch_get_main_queue(), { () -> Void in
cell.networkToggle.setOn(false, animated: true)
})
//code to deauthorize network
+ let tabBar = self.tabBarController
+ let didSucceed:Bool = ((tabBar as? HomeViewController)?.fbGraphManager.deAuthorizeApp(self))!
+ cell.networkToggle.on = !didSucceed
}
else{
@@ -434,11 +441,12 @@ extension NetworksTableViewController: UITableViewDelegate {
//this is the type of code desired to access the rest management classes
- let tabBar = self.tabBarController
- (tabBar as? HomeViewController)?.fbGraphManager.authorizeApp(self)
-
+ let tabBar = self.tabBarController
+ let didSucceed: Bool = ((tabBar as? HomeViewController)?.fbGraphManager.authorizeApp(self))!
+ cell.networkToggle.on = didSucceed
//self.fbGraphManager.authorizeApp(self)
+
}