如何在Rails Gem中使用LinkedIn的Share API

时间:2012-12-20 03:55:11

标签: ruby-on-rails xml ruby-on-rails-3 api linkedin

我正在使用LinkedIn API gem运行Rails 3:here

我无法按照here

所述的方式使Share API正常工作

这很好用:

response = client.add_share(:comment => 'new share API')

这失败了:

  response = client.add_share(:comment => 'new share API', :title => 'Linkedin Share API', :url => 'http://developer.linkedin.com/docs/DOC-1212', :image_url => 'http://images.bizjournals.com/travel/cityscapes/thumbs/sm_sanfrancisco.jpg')

错误:

LinkedIn::Errors::GeneralError ((400): Invalid xml {Expected elements 'post-network-update@http://api.linkedin.com/v1 id@http://api.linkedin.com/v1 visibility@http://api.linkedin.com/v1 comment@http://api.linkedin.com/v1 attribution@http://api.linkedin.com/v1 content@http://api.linkedin.com/v1 private-message@http://api.linkedin.com/v1 share-target-reach@http://api.linkedin.com/v1' instead of 'image-url@http://api.linkedin.com/v1' here in element share@http://api.linkedin.com/v1, Expected elements 'post-network-update@http://api.linkedin.com/v1 id@http://api.linkedin.com/v1 attribution@http://api.linkedin.com/v1 content@http://api.linkedin.com/v1 private-message@http://api.linkedin.com/v1 share-target-reach@http://api.linkedin.com/v1' instead of 'url@http://api.linkedin.com/v1' here in element share@http://api.linkedin.com/v1}):

有什么想法吗?感谢

1 个答案:

答案 0 :(得分:0)

你做错了。这是https://developer.linkedin.com/documents/share-api#toggleview:id=xml

中示例请求的XML
  <share>
  <comment>Check out the LinkedIn Share API!</comment>
  <content>
    <title>LinkedIn Developers Documentation On Using the Share API</title>
    <description>Leverage the Share API to maximize engagement on user-generated content on LinkedIn</description>
    <submitted-url>https://developer.linkedin.com/documents/share-api</submitted-url>
    <submitted-image-url>http://m3.licdn.com/media/p/3/000/124/1a6/089a29a.png</submitted-image-url> 
  </content>
  <visibility> 
    <code>anyone</code> 
  </visibility>
</share>

因此请求应该基于示例请求看起来像这样:

response = client.add_share(:comment => 'Sample Job',
                            :content => { :title => 'LinkedIn Developers Documentation On Using the Share API', :description => 'Leverage the Share API to maximize engagement on user-generated content on LinkedIn', :'submitted-url' => 'https://developer.linkedin.com/documents/share-api', :'submitted-image-url' => 'http://m3.licdn.com/media/p/3/000/124/1a6/089a29a.png' } )