如何使用swift 3在linkedin上分享帖子



我尝试了下面的代码,但它只打开了LinkedIn而不是共享。

我正在尝试使用Swift在iOS中集成领英SDK。

我试过了,但没用。请建议我如何在LinkedIn上分享帖子。

@IBAction func linkbtn(_ sender: Any) {
LISDKSessionManager.createSession(withAuth: [LISDK_BASIC_PROFILE_PERMISSION], state: nil, showGoToAppStoreDialog: true, successBlock: {(sucess) in
let session = LISDKSessionManager.sharedInstance().session
print("Session ",session!)
//let url = "https://api.linkedin.com/v1/people/~"
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: "aomething went wrong", preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(action)
self.present(alert, animated: true, completion: nil)
})
}
}) {(error) in
print("Error (String(describing: error))")
}
}

试试这个:-

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 ",session!)
//let url = "https://api.linkedin.com/v1/people/~"
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: "aomething went wrong", preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(action)
self.present(alert, animated: true, completion: nil)
})
}
}) {(error) in
print("Error (String(describing: error))")
}
}

确保您已在"应用程序设置身份验证"选项卡上启用w_share权限。并在Info.plist 上添加了所有必需的值

最新更新