IOSLinkedInAPI
IOSLinkedInAPI copied to clipboard
Swift version for Xcode 6.1
Here is what I did for swift in case anyone needs it. Note, this is using the fork that allows AFNetworking 1.x since RestKit requires that still.
// MARK: LinkedIn
var linkedInClient: LIALinkedInHttpClient {
let application = LIALinkedInApplication(redirectURL: "http://api.sessionradar.com/linkedin", clientId: kLinkedInClientId, clientSecret: kLinkedInClientSecret, state: kLinkedInState, grantedAccess: ["r_emailaddress"])
return LIALinkedInHttpClient(forApplication: application, presentingViewController: self)
}
@IBAction func didTapConnectWithLinkedIn(sender: AnyObject) {
self.linkedInClient.getAuthorizationCode({ (code: String!) -> Void in
self.linkedInClient.getAccessToken(code, success: { (accessTokenData: [NSObject: AnyObject]!) -> Void in
let accessToken = accessTokenData["access_token"] as String
let urlPath = "https://api.linkedin.com/v1/people/~/email-address?oauth2_access_token=\(accessToken)&format=json"
self.linkedInClient.getPath(urlPath, parameters: nil, success: { (operation: AFHTTPRequestOperation!, result: AnyObject!) -> Void in
self.showActivityIndicator()
let responseData = result as NSData!
let userEmail = NSString(data: responseData, encoding: NSUTF8StringEncoding)
// My Login code here that needs the LinkedIn Email
}, failure: { (operation, error) -> Void in
NSLog("error getting linked in data: \(error)")
})
}, failure: { (error) -> Void in
NSLog("error getting linked in access token: \(error)")
})
}, cancel: { () -> Void in
NSLog("LinkedIn authorization canceled")
}) { (error) -> Void in
NSLog("Error getting linkedin auth code: \(error)")
}
}
We can close this since it really isn't an active issue.
Hi, I am testing with your code in swift and I get an error saying that self.linkedInClient does not have function getPath. Have you added it yourself or I just haven't imported all in my bridging file ?
the getPath function is part of AFHTTPClient.h from which the LinkedInClient inherits.