Can not parse JSON share document.\nRequest body:\n\nError:\nnull

Can not parse JSON share document.\nRequest body:\n\nError:\nnull

我正在尝试向 Linkedin 的剩余分享发送请求 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 都不起作用

headers 词典中删除 content-type

requests 在使用 json 关键字参数时设置正确的内容类型。

你有三个基本问题:

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

  2. 分享URLdoes not take a oauth2_token argument.

  3. 你打错了content-typeheader.