ios – 如何将应用程序中的Linkedin SDK集成到使用Swift进行登录和共享

ios – 如何将应用程序中的Linkedin SDK集成到使用Swift进行登录和共享,第1张

概述我正在尝试使用 swift在iOS中集成LinkedIn SDK 我在Objective-C中找到了以下代码 我很快乐, 我尝试在swift中转换此代码,但它不起作用. Plz建议我如何在swift中转换下面的代码. 或者我如何整合Linkedin Sdk登录&使用swift通过我的应用分享.. enter code here[LISDKSessionManager createSessionW 我正在尝试使用 swift在iOS中集成linkedIn SDK

我在Objective-C中找到了以下代码

我很快乐,
我尝试在swift中转换此代码,但它不起作用.
Plz建议我如何在swift中转换下面的代码.
或者我如何整合linkedin Sdk登录&使用swift通过我的应用分享..

enter code here[liSDKSessionManager createSessionWithAuth:permissions state:nil showGoToAppStoreDialog:YES successBlock:^(Nsstring *returnState){ NSLog(@"%s","success called!"); liSDKSession *session = [[liSDKSessionManager sharedInstance] session]; NSLog(@"Session  : %@",session.description); [[liSDKAPIHelper sharedInstance] getRequest:@"https://API.linkedin.com/v1/people/~"                                        success:^(liSDKAPIResponse *response) { NSData* data = [response.data dataUsingEnCoding:NSUTF8StringEnCoding]; NSDictionary *dictResponse = [NSJsONSerialization JsONObjectWithData:data options:NSJsONReadingMutableContainers error:nil]; Nsstring *authUsername = [Nsstring stringWithFormat: @"%@ %@",[dictResponse valueForKey: @"firstname"],[dictResponse valueForKey: @"lastname"]]; NSLog(@"Authenticated user name  : %@",authUsername); [self.lblAuthenticatedUser setText: authUsername];  } error:^(liSDKAPIError *APIError) {   NSLog(@"Error  : %@",APIError);  }];  } errorBlock:^(NSError *error) {  NSLog(@"Error called  : %@",error); }];
解决方法 这就是我设法通过linkedIn验证用户的方法,使用SwiftyJsON库来解析响应. https://github.com/SwiftyJSON/SwiftyJSON
截至2015年5月,linkedIn限制访问其API,只允许访问基本个人资料字段/电子邮件.您还需要在开发人员控制台中的应用程序下为r_basicprofile和r_emailaddress设置基本权限,以使其正常工作.

希望这可以帮助

@IBAction func connectWithlinkedIn(sender: AnyObject) {  let url = Nsstring(string:"https://API.linkedin.com/v1/people/~:(ID,industry,firstname,lastname,emailAddress,headline,summary,publicProfileUrl,specialtIEs,positions:(ID,Title,start-date,end-date,is-current,company:(ID,name,type,size,ticker)),pictureUrls::(original),location:(name))?format=Json")    let permissions: [AnyObject] = [liSDK_BASIC_PROfile_PERMISSION,liSDK_EMAILADDRESS_PERMISSION]    liSDKSessionManager.createSessionWithAuth(permissions,state: nil,showGoToAppStoreDialog: true,successBlock: { (success) -> () in        if liSDKSessionManager.hasValIDSession() {            liSDKAPIHelper.sharedInstance().getRequest(url as String,success: {                response in                print(response)                print("successfully signed in")                dispatch_async(dispatch_get_main_queue(),{ () -> () in                    if let dataFromString = response.data.dataUsingEnCoding(NSUTF8StringEnCoding,allowLossyConversion: false) {                        let result = JsON(data: dataFromString)                        liSDKSessionManager.clearSession()                        //Do something with the response for example                        var picURL: String!                        for stringInArray in result["pictureUrls"]["values"]{                            let value = stringInArray.1.stringValue                            print(value)                            picURL = value                        }                       print(result["pictureUrls"]["values"].arrayValue)                       print(result["specialtIEs"].stringValue)                        }                })                },error: {                    error in                    liSDKAPIHelper.sharedInstance().cancelCalls()                    liSDKSessionManager.clearSession()                    print(error.localizedDescription)                    //Do something with the error            })        }        print("success called!")        },errorBlock: { (error) -> () in            print("%s","error called!")            liSDKAPIHelper.sharedInstance().cancelCalls()            liSDKSessionManager.clearSession()    })}
总结

以上是内存溢出为你收集整理的ios – 如何将应用程序中的Linkedin SDK集成到使用Swift进行登录和共享全部内容,希望文章能够帮你解决ios – 如何将应用程序中的Linkedin SDK集成到使用Swift进行登录和共享所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1048467.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存