使用 ios swift 3 在 linkedin 上分享 post 并且 linkedin sdk 不工作

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

我正在使用以下代码在使用 swift 3 的链接中共享 post,但出现以下错误。

代码

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 Domain=LISDKErrorAPIDomain Code=400 "(null)" UserInfo={LISDKAuthErrorAPIResponse=}

注意:我试过这个解决方案但没有帮助。 Share on Linkedin using the SDK for iOS doesn't work

找到解决方案,

问题出在我发送的负载上。使用以下有效载荷而不是使用上面的有效载荷。

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