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