无法解析JSON共享文档。\ n请求正文:\ n \ n错误:\ nnull

时间:2015-07-26 11:57:06

标签: python json linkedin linkedin-api

我正在尝试向Linkedin的rest share api发送请求。我一直收到此错误消息:

{
  "errorCode": 0,
  "message": "Can not parse JSON share document.\nRequest body:\n\nError:\nnull",
  "requestId": "ETX9XFEI7N",
  "status": 400,
  "timestamp": 1437910620120
}

请求通过以下python代码发送:

import requests,json


auth_token = "some auth token"

url = "https://api.linkedin.com/v1/people/~/shares?format=json&oauth2_access_token="+auth_token

headers = {'content-type': 'application/x-www-form-urlencoded','x-li-format':'json'}


data = {
              "comment":"Check out developer.linkedin.com!",
              "content":{
                        "title": "LinkedIn Developers Resources",
                        "description": "Leverage LinkedIn's APIs to maximize engagement",
                        "submitted-url": "https://developer.linkedin.com",  
                        "submitted-image-url": "https://example.com/logo.png"
                        },
              "visibility":{
                        "code": "anyone"
                           }
        }



response = requests.post( url , json= data , headers=headers )


return HttpResponse( response )

我确保我按照documentation中的所有说明操作,并且无法找到我所犯的错误。

注意:我试过json = data和data = data都不能正常工作

2 个答案:

答案 0 :(得分:0)

headers词典中删除requests

使用json关键字参数时,

<script type="text/javascript"> for(i=1;i<=50;i++){ document.write("<a href='page.html#"+i+">"+i+"</a>"); } </script> 设置正确的Content-Type。

答案 1 :(得分:0)

您有三个基本问题:

  1. 请阅读documentation on oauth2;因为你没有正确传递令牌。

  2. 共享网址does not take a oauth2_token argument

  3. 您的内容类型标题错误。