[英]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.