iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 如何将应用程序中的Linkedin SDK集成到使用Swift进行登录和共享大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用 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验证用户的@L_607_9@,使用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进行登录和共享所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。