AnderGoig / SwiftInstagram

Instagram API client written in Swift
https://git.io/vdNAn
MIT License
580 stars 79 forks source link

Unable to make requests #49

Open blackwiz4rd opened 6 years ago

blackwiz4rd commented 6 years ago

Checklist

Expected Behavior

Being able to make any request after login. Can't initialize data in request() -> urlSession.dataTask

Actual Behavior

Error when invoking api.userFollows(...): Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value Error when invoking getInstagramData()=api.user(...): decoding(message: "The data couldn’t be read because it is missing.") The operation couldn’t be completed. (SwiftInstagram.InstagramError error 0.)

Steps to Reproduce the Problem

  1. Login button action

` static func loginInstagram(from: UINavigationController, completion: @escaping (Error?) -> Void){ let api = Instagram.shared

    // Login
    //print("Instragam Login")
    api.login(from: from, withScopes: [.basic, .publicContent], success: {
        completion(nil)
    }, failure: { error in
        print(error.localizedDescription)
    })

} `

  1. Get data button action

` static func getInstagramData() { let api = Instagram.shared

    api.user("self", success: { userList in
        print(SwiftyJSON.JSON(userList))
    }, failure: { error in
        print(error)
        print(error.localizedDescription)
    })

} `

However this works: Alamofire.request("https://api.instagram.com/v1/users/self?access_token="+api.retrieveAccessToken()!).responseJSON(completionHandler: { response in if let result = response.result.value { let swiftyJSON = JSON(result) print(swiftyJSON) }

Specifications