我正在尝试通过REST API分享我的内容 . 后端 - Ruby / Rails
最初,我尝试宝石'linkedin','linkedin-oauth2',但我收到错误“访问发布分享被拒绝”
宝石'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')
宝石'linkedin-oauth2'
api = LinkedIn::API.new(access_token)
api.add_share(content: "hi")
然后我使用HTTParty按照这里的说明https://developer.linkedin.com/docs/share-on-linkedin,但再次得到错误"Access to posting shares denied" .
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的经验?
1 回答
试试这个