[英]share post on linkedin using ios swift 3 and linkedin sdk is not working
我正在使用以下代码在使用 swift 3 的链接中共享帖子,但它给出了以下错误。
代码
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))")
}
}
错误
错误域=LISDKErrorAPIDomain Code=400 "(null)" UserInfo={LISDKAuthErrorAPIResponse=}
注意:我尝试了这个解决方案,但没有帮助。 使用 iOS 版 SDK 在 Linkedin 上分享不起作用
找到了解决办法,
问题出在我发送的有效载荷上。 使用以下有效负载而不是使用上述负载。
let payloadStr: String = "{\"comment\":\"Check out developer.linkedin.com! http://linkd.in/1FC2PyG\",\"visibility\":{ \"code\":\"anyone\" }}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.