我试图通过REST API分享我的内容。 后端 - Ruby / Rails
最初,我尝试使用宝石' linkedin' linkedin-oauth2',但我收到错误"访问发布的内容被拒绝"
gem' linkedin'
consumer_options = {
:request_token_path => "/uas/oauth/requestToken?scope=r_basicprofile+rw_nus",
:access_token_path => "/uas/oauth/accessToken",
:authorize_path => "/uas/oauth/authorize",
:api_host => "https://api.linkedin.com",
:auth_host => "https://www.linkedin.com"
}
client = LinkedIn::Client.new('your_consumer_key', 'your_consumer_secret', consumer_options)
client.authorize_from_access(token, token_secret)
client.add_share(:comment => 'test gempost')
gem' linkedin-oauth2'
api = LinkedIn::API.new(access_token)
api.add_share(content: "hi")
然后我使用HTTParty按照此处https://developer.linkedin.com/docs/share-on-linkedin的说明进行操作,但得到错误"访问发布的内容被拒绝"试。
data = { comment: message, visibility: {code: 'anyone'} }
response = HTTParty.post("https://api.linkedin.com/v1/people/~/shares?format=json",
headers: { 'Content-Type' => 'application/json'},
query: {oauth2_access_token: linkedin_identity.token},
body: data.to_json)
我已经为我的应用程序授予了所有权限 - 这可能是导致此类错误的原因? 有没有人有通过API发布到Linkedin的经验?
答案 0 :(得分:0)
试试这个
data = { comment: message, visibility: {code: 'anyone'} }
response = HTTParty.post("https://api.linkedin.com/v1/people/~/shares?format=json",
headers: { 'Content-Type' => 'application/json',
'Authorization' => "Bearer #{your_access_token}"},
body: data.to_json
)