0

我正在尝试向 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 )

我确保我遵循了他们文档中的所有说明,并且找不到我所犯的错误。

注意:我试过 json=data 和 data=data 都不起作用

4

2 回答 2

0

content-typeheaders字典中删除。

requestsjson使用关键字参数时设置正确的 Content-Type 。

于 2015-07-26T12:33:58.987 回答
0

你有三个基本问题:

  1. 请阅读oauth2 上的文档;因为您没有正确传递令牌。

  2. 共享 URL不采用 oauth2_token 参数

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

于 2015-07-26T14:31:34.920 回答