2013-02-19 79 views
3

我試圖使用linkedin ruby api發送消息到API終點:http://api.linkedin.com/v1/people/~/shares,但每次出現此錯誤時:LinkedIn::Errors::AccessDeniedError ((403): Access to posting shares denied)。哪裏不對?使用linkedin api發佈公共消息時出現「發佈拒絕發佈的帖子」錯誤

代碼:

#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! 

我需要指定範圍的參數?如果是的話,我如何在我的代碼中實現這一點?

感謝

+0

你可以發佈你正在使用連接的代碼?如果LinkedIn返回適當的狀態代碼,這聽起來像您用來訪問API的帳戶沒有權限執行您想要的操作。 – 2013-02-19 11:59:53

+0

哥們你發佈了你的應用的祕密 – Dan 2013-05-02 13:39:11

+0

@丹這是假的:P – serpent403 2013-05-03 08:52:56

回答

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) 
+0

感謝您的答案! – bragboy 2013-02-22 13:40:23

+0

感謝它爲我工作 – babu 2015-07-14 08:57:01