FBSDK访问令牌字符串始终为零

时间:2016-10-12 17:08:29

标签: ios django swift facebook fbsdk

我正在构建一个使用Facebook进行用户登录的iOS应用程序,然后将令牌传递给我的django Web服务器以转换为访问令牌。问题是FBSDK访问令牌正在出现并且可以使用但在尝试访问它的字符串值时显示为nil,这可以在此函数中看到。我一直在努力寻找问题,所以任何形式的帮助都会非常感激。

func login(userType: String, completionHandler: @escaping (NSError?) -> Void) {
        let path = "api/social/convert-token"
        let url = baseURL!.appendingPathComponent(path)
        let params: [String: Any] = [
            "grant_type": "convert-token",
            "client_id": CLIENT_ID,
            "client_secret": CLIENT_SECRET,
            "backend": "facebook",
            "token": FBSDKAccessToken.current().tokenString!,
            "user_type": userType
        ]
        /* Does appear */ print("THE TOKEN NO STRING IS \(FBSDKAccessToken.current()")
        /* Shows as nil */ print(" THE TOKEN IS \(FBSDKAccessToken.current().tokenString!)")

        Alamofire.request(url!, method: .post, parameters: params, encoding: URLEncoding(), headers: nil).responseJSON { (response: DataResponse<Any>) in
            switch response.result {
            case .success(let value):
                let jsonData = JSON(value)
                self.accessToken = jsonData["access_token"].string!
                self.refreshToken = jsonData["refresh_token"].string!
                self.expired = Date().addingTimeInterval(TimeInterval(jsonData["expires_in"].int!))
                completionHandler(nil)
                break
            case .failure(let error):
                completionHandler(error as NSError?)
                break
            }
        }
    }

0 个答案:

没有答案