如何将LinkedIn的共享API与Rails Gem一起使用



我正在运行rails 3,带有LinkedIn Api Gem:此处

我一直无法使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}):

有什么想法吗?谢谢

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

中的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' } )

最新更新