emorikawa / linkedin-oauth2

Ruby wrapper for the LinkedIn OAuth2 API
Other
70 stars 86 forks source link

Error when attempting to add a company share #16

Closed leesmith closed 10 years ago

leesmith commented 10 years ago

I'm trying to post some content as a company share to a LinkedIn company page. After getting authenticated through OAuth2 and obtaining the access token, I can successfully query for things via the api. When I try to write to the company page however, I get a no implicit conversion of Symbol into Integer error.

My offending line:

api.add_company_share(2414183, comment: 'Test company share')

I've tried posting to LinkedIn's test company page (as stated in the red box at the top of this page https://developer.linkedin.com/creating-company-shares) as well as the company page I'm an admin for.

What's interesting is that the twitter gem is actually throwing the error (I'm using the twitter gem in this project as well):

TypeError - no implicit conversion of Symbol into Integer:
  twitter (5.11.0) lib/twitter/error.rb:75:in `parse_error'
  twitter (5.11.0) lib/twitter/error.rb:39:in `from_response'
  twitter (5.11.0) lib/twitter/rest/response/raise_error.rb:15:in `on_complete'
  faraday (0.9.0) lib/faraday/response.rb:9:in `block in call'
  faraday (0.9.0) lib/faraday/response.rb:57:in `on_complete'
  faraday (0.9.0) lib/faraday/response.rb:8:in `call'
  faraday (0.9.0) lib/faraday/adapter/net_http.rb:54:in `call'
  faraday (0.9.0) lib/faraday/request/url_encoded.rb:15:in `call'
  faraday (0.9.0) lib/faraday/rack_builder.rb:139:in `build_response'
  faraday (0.9.0) lib/faraday/connection.rb:377:in `run_request'
  faraday (0.9.0) lib/faraday/connection.rb:177:in `post'
  linkedin-oauth2 (1.0.0) lib/linked_in/api_resource.rb:53:in `post'
  linkedin-oauth2 (1.0.0) lib/linked_in/companies.rb:99:in `add_company_share'
  /Users/lsmith/.rbenv/versions/2.1.2/lib/ruby/2.1.0/forwardable.rb:183:in `add_company_share'

I've examined the api object that gets built and I notice that Twitter has registered itself as a handler to the Faraday::RackBuilder object to raise errors...or something:

>> api
=> #<LinkedIn::API:0x007fa5934a8810 @access_token=#<LinkedIn::AccessToken:0x007fa5934a8838 @token="x", @expires_in=5181715, @expires_at=1418701297>, @connection=#<LinkedIn::Connection:0x007fa5934a8608 @parallel_manager=nil, @headers={"x-li-format"=>"json", "User-Agent"=>"Faraday v0.9.0"}, @params={"oauth2_access_token"=>"x"}, @options=#<Faraday::RequestOptions params_encoder=Faraday::FlatParamsEncoder>, @ssl=#<Faraday::SSLOptions verify=true>, @default_parallel_manager=nil, @builder=#<Faraday::RackBuilder:0x007fa5934a81a8 @handlers=[Faraday::Request::UrlEncoded, Faraday::Adapter::NetHttp, Twitter::REST::Response::RaiseError], @app=#<Faraday::Request::UrlEncoded:0x007fa5934a2488 @app=#<Faraday::Adapter::NetHttp:0x007fa5934a2578 @app=#<Twitter::REST::Response::RaiseError:0x007fa5934a2690 @app=#<Proc:0x007fa5934a28e8@/Users/lsmith/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:152 (lambda)>>>>>, @url_prefix=#<URI::HTTPS:0x007fa5934a3900 URL:https://api.linkedin.com/v1>, @proxy=nil>, @jobs=#<LinkedIn::Jobs:0x007fa5934a2f78 @connection=#<LinkedIn::Connection:0x007fa5934a8608 @parallel_manager=nil, @headers={"x-li-format"=>"json", "User-Agent"=>"Faraday v0.9.0"}, @params={"oauth2_access_token"=>"x"},

As far as being able to post some content to a LinkedIn company page, what am I doing wrong? Thanks for any help!

leesmith commented 10 years ago

I commented out the twitter gem and I'm now seeing the true error...400 response.

However, my issue looks an awful lot like this one: https://github.com/emorikawa/linkedin-oauth2/issues/11

leesmith commented 10 years ago

I've created a pull request to fix the json.

However, I'm still not sure that the twitter gem should be reporting errors. Maybe https://github.com/emorikawa/linkedin-oauth2/pull/15 will correct this?