简体   繁体   English

我如何从 iOS 应用程序在 Linkedin 上分享帖子

[英]How can i share post on Linkedin from iOS app

Here is my scenario.这是我的场景。 I have my valid accessToken , which I have already used to retrieve info from user profile.我有我的有效accessToken ,我已经用它来从用户配置文件中检索信息。 Below is the steps I have been trying to post using that token.以下是我尝试使用该令牌发布的步骤。 I have been receiving statusCode = 401我一直在收到statusCode = 401

linkedinHelper.authorizeSuccess({ [unowned self] (lsToken) -> Void in

        self.writeConsoleLine("Login success lsToken: \(lsToken)")
        print("\(lsToken.accessToken ?? "")")
        let targetURLString = "https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=\(lsToken.accessToken ?? "")&format=json"
        let payloadStr: String = "{\"comment\":\"Check out developer.linkedin.com!\",\"visibility\":{\"code\":\"anyone\"}}"

        // Initialize a mutable URL request object.
        let request = NSMutableURLRequest(url: NSURL(string: targetURLString)! as URL)

        // Indicate that this is a GET request.
        request.httpMethod = "POST"
        request.httpBody = payloadStr.data(using: String.Encoding.utf8)
        // Add the access token as an HTTP header field.
        request.addValue("Bearer \(lsToken.accessToken ?? "")", forHTTPHeaderField: "Authorization")
        request.addValue("application/json", forHTTPHeaderField: "Content-Type")
        request.addValue("json", forHTTPHeaderField: "x-li-format")

        // Make the request.
        let task: URLSessionDataTask = URLSession.shared.dataTask(with: request as URLRequest) { (data, response, error) -> Void in
            // Get the HTTP status code of the request.
            let statusCode = (response as! HTTPURLResponse).statusCode

            if statusCode == 201 {
                // Convert the received JSON data into a dictionary.

                guard ((try? JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers)) as? [String: Any]) != nil else {
                    print("Not containing JSON")
                    return
                }

                print("successfully posted.")
            }
        }
        task.resume()
    }, error: { [unowned self] (error) -> Void in

        self.writeConsoleLine("Encounter error: \(error.localizedDescription)")
    }, cancel: { [unowned self] () -> Void in

        self.writeConsoleLine("User Cancelled!")
    })

LinkedIn v1 API is no longer supported.不再支持 LinkedIn v1 API。 You will need to use their v2 APIs: https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/share-on-linkedin?context=linkedin/consumer/context您将需要使用他们的 v2 API: https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/share-on-linkedin?context=linkedin/consumer/context

Your target URL should use the ugcPosts endpoint:您的目标 URL 应该使用 ugcPosts 端点:

POST https://api.linkedin.com/v2/ugcPosts

In addition to Christopher's point, I'm afraid Linkedin doesn't appear to be processing the queue of people waiting for access to v2 of the API - we requested access 5 months ago, nothing has changed.除了克里斯托弗的观点之外,恐怕 Linkedin 似乎并没有处理等待访问 API v2 的人的队列——我们在 5 个月前请求访问,没有任何改变。 We were using v1 of the API for 2 years without any issues, then one day they switched us off with no method of getting transferred to the new API.我们使用 API 的 v1 2 年没有任何问题,然后有一天他们关闭了我们,没有办法转移到新的 API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过iOS应用在LinkedIn上共享URL - Share an URL on LinkedIn from an iOS app 如何通过iOS应用程序将URL分享给linkedIn - How to share a URL to linkedIn via iOS app 如何通过iOS应用在Google+上共享内容? - How can I share something on Google+ from an iOS app? 如何将 url 从浏览器共享到 iOS 中的应用程序? - How can I share a url from a browser to my app in iOS? 如何将我的应用中的帖子分享到 Twitter iOS - How to share a post from my app to twitter iOS 如何通过iOS应用程序将现有的Facebook帖子分享到用户时间轴? - How to share an existing facebook post to user timeline from an iOS app? 使用ios swift 3 在linkedin 上分享帖子并且linkedin sdk 不起作用 - share post on linkedin using ios swift 3 and linkedin sdk is not working App Extension iOS9:如何从共享视图向我的应用程序发送字符串/ URL? - App Extension iOS9: How can I send a string / URL from the share view to my the app? 如何直接从 iOS 共享表打开我的应用程序? 嘿 - How can I open my app directly from the iOS Share Sheet? Hey 如何通过iOS应用程序通过电子邮件和消息共享字符串? - How can I share a string through email and imessage from my iOS app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM