"访问发布的股票被拒绝"使用linkedin api发布公共消息时出错

时间:2013-02-19 11:48:22

标签: ruby-on-rails ruby linkedin

我正在尝试使用linkedin ruby api向API端点发送消息:http://api.linkedin.com/v1/people/~/shares,但每次出现此错误时都会LinkedIn::Errors::AccessDeniedError ((403): Access to posting shares denied)。怎么了?

代码:

#fetch client object
client = LinkedIn::Client.new('er0xev11ktyj', 'qw7hfgR4wT8Hztpl')

#auth
request_token = client.request_token(:oauth_callback => callback_url)
session[:linkedin_token] = request_token.token
session[:linkedin_secret] = request_token.secret
redirect_to request_token.authorize_url

#inside callback url
atoken,asecret = client.authorize_from_request(session[:linkedin_token], session[:linkedin_secret], params[:oauth_verifier])

#api call for posting message
client.authorize_from_access(atoken, asecret)
client.add_share({:comment => "Hey!"}) #throws error!

我是否需要指定范围参数?如果是,我如何在我的代码中实现它?

由于

1 个答案:

答案 0 :(得分:5)

覆盖默认的使用者选项并将范围附加到request_token_path

 consumer_options = {
    :request_token_path => "/uas/oauth/requestToken?scope=r_basicprofile+w_share",
    :access_token_path  => "/uas/oauth/accessToken",
    :authorize_path     => "/uas/oauth/authorize",
    :api_host           => "https://api.linkedin.com",
    :auth_host          => "https://www.linkedin.com"
  }
 LinkedIn::Client.new(ckey, csecret, consumer_options)