简体   繁体   English

使用ios swift 3 在linkedin 上分享帖子并且linkedin sdk 不起作用

[英]share post on linkedin using ios swift 3 and linkedin sdk is not working

I am using the following code to share the post in linked in using swift 3 but it is giving the following error.我正在使用以下代码在使用 swift 3 的链接中共享帖子,但它给出了以下错误。

Code代码

func shareOnLinkedIn(){
    LISDKSessionManager.createSession(withAuth:
        [LISDK_BASIC_PROFILE_PERMISSION,LISDK_W_SHARE_PERMISSION], state: nil, showGoToAppStoreDialog: true, successBlock: {(sucess) in
            let session = LISDKSessionManager.sharedInstance().session
            print(session?.description)
            //let url = "https://api.linkedin.com/v1/people/~"

            LISDKAPIHelper.sharedInstance()?.getRequest("https://api.linkedin.com/v1/people/~", success: { (response) in

                if let response = response{
                    let data = response.data.data(using: .utf8)
                    let dictResponse = try! JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! NSDictionary

                    DispatchQueue.main.async {
                        if LISDKSessionManager.hasValidSession(){
                            let url: String = "https://api.linkedin.com/v1/people/~/shares"

                            let payloadStr: String = "{\"comment\":\"YOUR_APP_LINK_OR_WHATEVER_YOU_WANT_TO_SHARE\",\"visibility\":{\"code\":\"anyone\"}}"

                            let payloadData = payloadStr.data(using: String.Encoding.utf8)


                            LISDKAPIHelper.sharedInstance().postRequest(url, body: payloadData, success: { (response) in
                                print(response!.data)
                            }, error: { (error) in
                                print(error!)

                                let alert = UIAlertController(title: "Alert!", message: "something went wrong", preferredStyle: .alert)
                                let action = UIAlertAction(title: "OK", style: .default, handler: nil)

                                alert.addAction(action)
                                self.present(alert, animated: true, completion: nil)
                            })
                        }
                    }

                }

            }, error: { (error) in
                print(error?.localizedDescription as Any)
            })


    }) {(error) in
        print("Error \(String(describing: error))")
    }
}

Error错误

Error Domain=LISDKErrorAPIDomain Code=400 "(null)" UserInfo={LISDKAuthErrorAPIResponse=}错误域=LISDKErrorAPIDomain Code=400 "(null)" UserInfo={LISDKAuthErrorAPIResponse=}

Note: I tried this solution but doesn't help.注意:我尝试了这个解决方案,但没有帮助。 Share on Linkedin using the SDK for iOS doesn't work 使用 iOS 版 SDK 在 Linkedin 上分享不起作用

Found the solution,找到了解决办法,

The problem is with the payload which I am sending.问题出在我发送的有效载荷上。 Use the following payload instead of using the above.使用以下有效负载而不是使用上述负载。

 let payloadStr: String = "{\"comment\":\"Check out developer.linkedin.com! http://linkd.in/1FC2PyG\",\"visibility\":{ \"code\":\"anyone\" }}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM