拼多多查询商品详情接口 pdd.goods.detail.get 的授权问题

更新日期: 2019-09-29 阅读次数: 22989 字数: 508 分类: 广告联盟

今天有微信好友问如何调用拼多多 API 获取指定商品的详情明细。

我之前只用过多多客的返利 API 获取商品详情,但是对于不支持返利的商品来说,用这个接口是查询不到的。

于是查看了一下拼多多开发平台中关于商品明细接口 pdd.goods.detail.get 的说明,里面注明了必须用户授权,需要用户授权才能拿到被授权的数据。另外,里面提到“新增商品或者修改商品的时候”使用,所以我猜测,每个商家只能通过接口查询自己的商品,而无法查询其他商家的商品。当然,我这只是猜测。

https://open.pinduoduo.com/#/apidocument/port?portId=pdd.goods.detail.get

不死心,我决定用我的多多客应用的 client_id 去查询商品详情,看看能否查到。

获取授权 code

授权方式文档

https://open.pinduoduo.com/#/document?url=https%253A%252F%252Fmai.pinduoduo.com%252Fautopage%252F83_static_3%252Findex.html

授权链接格式

https://jinbao.pinduoduo.com/open.html?client_id=xxx&response_type=code&redirect_uri=https://www.sunzhongwei.com

点击授权即可。如果授权成功,会返回这样的地址

https://www.sunzhongwei.com/?code=xxx

获取 access token

将上一步获取到的 code 填写进去,在命令行中调用

curl -X POST -H "Content-Type: application/json" -d '{
                                     "client_id": "xxx",
                                     "code": "xxx",
                                     "grant_type": "authorization_code",
                                     "client_secret": "xxx"
                                     }' "http://open-api.pinduoduo.com/oauth/token"

会得到返回

{
  "scope": [
    "pdd.ddk.oauth.cms.prom.url.generate",
    "pdd.ddk.coupon.info.query",
    "pdd.ddk.order.detail.get",
    "pdd.util.divide.image",
    "pdd.ddk.all.order.list.increment.get",
    "pdd.ddk.lottery.url.gen",
    "pdd.ddk.oauth.weapp.\rqrcode.url.gen",
    "pdd.ddk.oauth.lottery.url.gen",
    "pdd.goods.cps.unit.create",
    "pdd.goods.cps.mall.unit.change",
    "pdd.goods.opt.get",
    "pdd.ddk.oauth.finance.cpa.query",
    "pdd.goods.cps.mall.unit.query",
    "pdd.ddk.goods.zs.\runit.url.gen",
    "pdd.goods.cps.mall.unit.resume",
    "pdd.goods.cps.unit.query",
    "pdd.ddk.goods.promotion.url.generate",
    "pdd.ddk.goods.search",
    "pdd.ddk.register.sms.vcode.send",
    "pdd.ddk.oauth.order.detail.get",
    "pdd.ddk.p\rhrase.generate",
    "pdd.ddk.oauth.theme.prom.url.generate",
    "pdd.ddk.goods.pid.generate",
    "pdd.ddk.oauth.check.in.bill.incr.get",
    "pdd.ddk.oauth.top.goods.list.query",
    "pdd.goods.cps.unit.delete",
    "pdd.ddk.comment.url.gen\rerate",
    "pdd.ddk.oauth.comment.url.generate",
    "pdd.ddk.oauth.rp.prom.url.generate",
    "pdd.ddk.goods.basic.info.get",
    "pdd.ddk.oauth.order.list.increment.get",
    "pdd.goods.cps.unit.change",
    "pdd.ddk.goods.detail",
    "pdd.ddk.\roauth.goods.prom.url.generate",
    "pdd.goods.cps.mall.unit.pause",
    "pdd.ddk.theme.list.get",
    "pdd.ddk.merchant.list.get",
    "pdd.ddk.ddjb.user.register",
    "pdd.ddk.cms.prom.url.generate",
    "pdd.ddk.goods.game.virtual.url.gene\rrate",
    "pdd.ddk.goods.sale.month.query",
    "pdd.ddk.top.goods.list.query",
    "pdd.ddk.oauth.goods.recommend.get",
    "pdd.ddk.goods.pid.query",
    "pdd.ddk.goods.recommend.get",
    "pdd.ddk.theme.prom.url.generate",
    "pdd.ddk.oauth.ap\rp.new.bill.list.get",
    "pdd.time.get",
    "pdd.ddk.oauth.goods.pid.query",
    "pdd.ddk.order.list.range.get",
    "pdd.ddk.order.list.increment.get",
    "pdd.util.divide.base64.image",
    "pdd.ddk.mall.goods.list.get",
    "pdd.ddk.oauth.res\rource.url.gen",
    "pdd.ddk.resource.url.gen",
    "pdd.ddk.goods.unit.query",
    "pdd.ddk.theme.goods.search",
    "pdd.ddk.rp.prom.url.generate",
    "pdd.ddk.goods.guess.like",
    "pdd.ddk.mall.url.gen",
    "pdd.ddk.weapp.qrcode.url.gen",
    "pd\rd.goods.cats.get",
    "pdd.ddk.oauth.goods.zs.unit.url.gen",
    "pdd.goods.cps.mall.unit.create",
    "pdd.ddjb.order.get",
    "pdd.ddk.finance.cpa.query",
    "pdd.ddk.oauth.mall.url.gen",
    "pdd.ddk.oauth.goods.pid.generate",
    "pdd.ddk.oauth.phrase.generate"
  ],
  "access_token": "xxx",
  "expires_in": 15551867,
  "expires_at": 1585301165,
  "refresh_token_expires_in": 15551867,
  "refresh_token_expires_at": 1585301165,
  "r1_expires_in": 15551867,
  "r2_expires_in": 15551867,
  "w1_expires_in": 15551867,
  "w2_expires_in": 15551867,
  "r1_expires_at": 1585301165,
  "r2_expires_at": 1585301165,
  "w1_expires_at": 1585301165,
  "w2_expires_at": 1585301165,
  "refresh_token": "xxx",
  "owner_id": "xxx",
  "owner_name": "xxx"
}

里面包含了 access_token 和 refresh_token。

从 scope 中看,确实没有pdd.goods.detail.get 的调用权限。

测试商品查询接口

在拼多多测试工具页

https://open.pinduoduo.com/#/apitools

拼多多查询商品详情接口 pdd.goods.detail.get 的授权问题

按提示填写对应的信息,查询结果。。。

拼多多查询商品详情接口 pdd.goods.detail.get 的授权问题

看来还是得用商家应用才有权限调用。

code已过期

{"error_response":{"error_code":10013,"error_msg":"code已过期"}} 

微信关注我哦 👍

大象工具微信公众号

我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式