New LinkedIn API Bug with /v1/person/~/shares (v0.2.2) #69

Closed
hundredwatt opened this Issue Sep 28, 2011 · 3 comments

Comments

Projects
None yet
3 participants
@hundredwatt
Collaborator

hundredwatt commented Sep 28, 2011

I've been using the #share method to post shares to people's profiles using the following code:

  client = LinkedIn::Client.new(...)
  client.authorize_from_access(...)
  client.share(:comment => "Hello World")

Starting sometime this weekend, LinkedIn's API began returning a 500 response to every attempt I made at this request. I posted this to their developer forum and they responded that its a bug on their end related to XML parsing: https://developer.linkedin.com/forum/getting-500-error-response-v1peopleshares

By trial and error, I figured out a way to get the above code working again. With just a comment, you can remove the content node in the XML. I monkey patched the #share_to_xml function to implement this work around:

LinkedIn::Client.class_eval {
  private
  def share_to_xml(options={})
    doc = Nokogiri.XML('<share><comment/><content><title/><submitted-url/><submitted-image-url/></content><visibility><code/></visibility></share>')
    doc.encoding = 'UTF-8'

    {:comment => 'comment', :title => 'title', :url => 'submitted-url', :image_url => 'submitted-image-url'}.each do |key, name|
    doc.at_css(name).content = options[key] if options[key]
    end

    doc.at_css('visibility > code').content = options[:visibility] || options[:visability] # backward-compatible typo fix

    ### MONKEY ###
    content_fields = [:title, :url, :image_url]
    unless options.values_at(content_fields).compact.any?
     doc.xpath('//content').remove
    end
    ### MONKEY ###

    doc.to_xml
  end
}

I asked on the forum if they are going to fix the issue. If they respond and say they aren't or don't respond, I can do a proper patch and submit a Pull Request

@ekampp

This comment has been minimized.

Show comment Hide comment
@ekampp

ekampp Oct 9, 2013

@hundredwatt is this still relevant?

ekampp commented Oct 9, 2013

@hundredwatt is this still relevant?

@hundredwatt

This comment has been minimized.

Show comment Hide comment
@hundredwatt

hundredwatt Oct 10, 2013

Collaborator

@ekampp I haven't tested again, but I also never heard back if this had been fixed

Collaborator

hundredwatt commented Oct 10, 2013

@ekampp I haven't tested again, but I also never heard back if this had been fixed

@hexgnu

This comment has been minimized.

Show comment Hide comment
@hexgnu

hexgnu Oct 13, 2013

Owner

It works if you use add_share

Owner

hexgnu commented Oct 13, 2013

It works if you use add_share

@hexgnu hexgnu closed this Oct 13, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment