I am trying to share a url, image and a text to linkedin through my app. But it shows an error as
The operation couldn’t be completed. (LISDKErrorAPIDomain error 403.)
My code is
func didLinkedinBtnPressed(cellObject: MyModel) {
let tmp = ["comment": cellObject.strSocialText!,
"content": ["title":"AppName", "description":cellObject.strSocialText!,"submitted-url":cellObject.strWebSite!,"submitted-image-url":cellObject.strImageUrl!],"visibility": ["code": "anyone"]] as [String : Any]
print("PostDtaa = \(tmp)")
let postData = try? JSONSerialization.data(withJSONObject: tmp, options: .prettyPrinted)
let url = NSString(string:"https://api.linkedin.com/v1/people/~/shares?format=json")
let permissions: [AnyObject] = [LISDK_BASIC_PROFILE_PERMISSION as AnyObject, LISDK_EMAILADDRESS_PERMISSION as AnyObject,LISDK_W_SHARE_PERMISSION as AnyObject]
LISDKSessionManager.createSession(withAuth: permissions, state: nil, showGoToAppStoreDialog: true, successBlock: { (success) -> () in
if LISDKSessionManager.hasValidSession() {
LISDKAPIHelper.sharedInstance().postRequest(url as String, body: postData, success: { (_ response) in
print(response ?? "")
self.simpleAlert(titleOfAlert: "Success", messageOfAlert: "Shared Successfully")
LISDKAPIHelper.sharedInstance().cancelCalls()
LISDKSessionManager.clearSession()
}, error: { (_errorRes) in
print(_errorRes?.localizedDescription ?? "No Error!!!")
LISDKAPIHelper.sharedInstance().cancelCalls()
LISDKSessionManager.clearSession()
})
}
}, errorBlock: { (error) -> () in
print("%s", "error called!")
LISDKAPIHelper.sharedInstance().cancelCalls()
LISDKSessionManager.clearSession()
})
}
Why am i getting a 403 error here?
I experimented a similar issue in the past it was related to the w_share permission
from the linkedin doc
Required permission: w_share
Whether set as a default permission in your app settings or requested specifically via the scope argument during your authentication process, you will need to request the w_share member permission in order for your application to successfully make the API call to share content.
w_share is disabled by default so it has to be explicitly enabled
NOTE: the token could be cached by app so in order to be sure that a new token (with the updated permissions) is used, I strongly suggest you to uninstall everything from your mobile device and re-install it again.