Share on Linkedin using the SDK for iOS doesn'

2019-02-25 23:04发布

问题:

I'm using the mobile SDK for iOS (Version:1.0.7) to share something on LinkedIn. I can get the current account information, but when I try to share on LinkedIn,it always feedback the error description. This is my code:

let url:String = "https://api.linkedin.com/v1/people/~/shares"
let payload:String = "{\"comment\":\"Check out developer.linkedin.com! http://linkd.in/1FC2PyG\",\"visibility\":{\"code\":\"anyone\"}}"
if LISDKSessionManager.hasValidSession(){
    LISDKAPIHelper.sharedInstance().postRequest(url, stringBody: payload, success: { (response) -> Void in
          print("\(response.data)")
          }, error: { (apiError) -> Void in
          print("\(apiError.description)")
     })

Has anyone ever facing the same issue. Please help me,thanks a lot!

回答1:

This works in Swift:-

        if LISDKSessionManager.hasValidSession() {

        LISDKAPIHelper.sharedInstance().postRequest(url, stringBody: payload, success: {
            response in
            //Do something with the response
            print("\(response.data)")

            }, error: {
                error in
                //Do something with the error
                print("\(error.description)")
        })
    }


回答2:

I had the same problem when I didn't set the correct permissions.

Make sure create session with share permissions.

let permissions = [LISDK_BASIC_PROFILE_PERMISSION, LISDK_W_SHARE_PERMISSION]
LISDKSessionManager.createSession(withAuth: permissions, state: nil, showGoToAppStoreDialog: true, successBlock: ...