java:从淘宝获取优惠券的、带推广链接的、带淘口令的商品信息
程序员文章站
2023-12-22 14:20:16
...
必要准备
实现步骤
- 完成阿里妈妈账号注册、及网站或无线APP备案审核通过(获取App Key、App Secret):
阿里妈妈账号注册
推广管理
进入淘宝联盟—>推广管理—>推广资源管理—>媒体管理—>网站或APP—>新建网站或APP推广(详细填写网站或APP的信息),提交后,若审核通过会后提示“审核通过”。
- 审核通过后,点击对应的网站或APP推广,查看获得的相应的权限,申请淘宝客【推广者】物料搜索权限。
在该页面上方APP证书一栏即可获取到App Key、App Secret。
审核通过后,在SDK下载处,点击生成新的SDK包并点击"立即下载"获取到相应权限下的jar包。 -
获取推广位ID
首先通过商品推广页面随便选择一个商品,选择"立即推广",然后设置推广位信息。
商品推广
在推广位管理中,找到pid,格式为mm_123_456_789,789位即为推广位id。
推广位管理
- 获取带优惠券的、带推广链接的、带淘口令的商品信息。
创建JAVA项目,引入下载的SDK.jar。根据淘宝开发平台接口文档编码获取商品信息。
淘宝开发API
import java.util.List;
import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.TbkDgMaterialOptionalRequest;
import com.taobao.api.request.TbkTpwdCreateRequest;
import com.taobao.api.response.TbkDgMaterialOptionalResponse;
import com.taobao.api.response.TbkDgMaterialOptionalResponse.MapData;
import com.taobao.api.response.TbkTpwdCreateResponse;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
String url = "http://gw.api.taobao.com/router/rest";
String appkey="12345678";
String secret="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
TbkDgMaterialOptionalRequest req = new TbkDgMaterialOptionalRequest();
req.setAdzoneId(1234567890L);
req.setSort("total_sales_asc");
req.setPageNo(1L);
req.setPageSize(5L);
req.setQ("女装");
req.setHasCoupon(true);
try {
TbkDgMaterialOptionalResponse execute = client.execute(req);
List<MapData> resultList = execute.getResultList();
System.out.println("一共有多少件商品:"+execute.getTotalResults());
for(MapData md:resultList) {
// 获取淘口令
TbkTpwdCreateRequest reqs = new TbkTpwdCreateRequest();
reqs.setText(md.getTitle());
reqs.setUrl("https:"+md.getCouponShareUrl());
TbkTpwdCreateResponse rsps = client.execute(reqs);
String exchangeCode = rsps.getData().getModel();
System.out.println("商品标题:"+md.getTitle()+",淘口令:"+exchangeCode+"优惠券:"+md.getCouponShareUrl());
}
} catch (ApiException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
控制台输出:
一共有多少件商品:1483370
商品标题:IBYI乙佰乙纳女装单排扣中长款宽松保暖羊毛呢外套女风衣大衣,淘口令:¥8fTS1fC3M77¥优惠券://uland.taobao.com/coupon/edetail?e=QfOJmNqcH3ENfLV8niU3RwXoB%2BDaBK5LQS0Flu%2FfbSog%2BeE%2BjpQFGNpsAmOX0u61tVNRlA%2Fi6pALsyrQoeEkOpNcV6ZxcHiRdc3puin9a5QLVXhMzg5SrNybh3E2uafZurTNHiRsB8W%2FOyLc7Z2VpY9Wna8TFLs6txl6Um37OPILsyrQoeEkOlUakXkdy2tUhYGr%2FJ2STgwxda%2Bv6BuDS0gfTscre%2FnAzWuH7hCAmylMDQVG07AK7A%3D%3D&&app_pvid=59590_11.132.118.96_605_1582515022334&ptl=floorId:2836;app_pvid:59590_11.132.118.96_605_1582515022334;tpp_pvid:100_11.30.123.20_1481_9201582515022338174&xId=26GcCFOrk4X5COOkubmCpwULsuPqNIo2CoBfP9E6dsaYTVfP2MAbZJaI3UTa9Epb1we1UounrxvqUPwPFpg1vj4RgOIOkFGFpP4KiaiJ2bK7&union_lens=lensId%3AMAPI%401582515022%400b847660_0e44_170753eea66_534b%4001
商品标题:摩登美眉春装2020新款女装长袖打底衫韩版大码蕾丝连衣裙镂空上衣,淘口令:¥HjwV1fCepzL¥优惠券://uland.taobao.com/coupon/edetail?e=qLV34m0DRKoNfLV8niU3RwXoB%2BDaBK5LQS0Flu%2FfbSpinP2GYChM67sPlpg2KVNfy5FOJP2gSFX%2FjE4MyFlOrN%2FbtuWRaZl7q%2Fx%2F7DcER2t1zem6Kf1rlAtVeEzODlKs3JuHcTa5p9m6tM0eJGwHxb87ItztnZWlj1adrxMUuzq3GXpSbfs48vqIF6phWLrJ6%2B7jZ776EFEn1RYiG96bU0GlmfJGHnwj8ibbZxVXWR47mmMWJDI59WUFFgz3RBVH&&app_pvid=59590_11.132.118.96_605_1582515022334&ptl=floorId:2836;app_pvid:59590_11.132.118.96_605_1582515022334;tpp_pvid:100_11.30.123.20_1481_9201582515022338174&xId=lQPqoWO89dlH3YCkQXD0AOSx3ORJEbuJje8J5zAsBMVHJvdbU3HCS6i1ZEm0sU6Syv4QAUX2emZDCIHbm76E04Fhm2tA0SgHI9QJZ7pq4DA&union_lens=lensId%3AMAPI%401582515022%400b847660_0e44_170753eea66_534c%4001
商品标题:300斤中年胖妈妈装特大码女装中长款外套秋装中老年奶奶240冬装,淘口令:¥9jBE1fC3HsA¥优惠券://uland.taobao.com/coupon/edetail?e=FSHqoC2NBowNfLV8niU3RwXoB%2BDaBK5LQS0Flu%2FfbSp4QsdWMikAalrisGmre1Id522H2TxuqpL7CbfkoKoaBMlLhZ%2BbuifePkDM1Gs7PuaIhWItbhr9R2XeTvVPHYgI50LPWpmdILusDadHJWJ6Vc9oFtlxk5sJgh2BOH8DuKswj7D0T0AbSWWcQ5Y%2BAeSBm1hkrcmebl2DipeAfzRHANPZ9T9I%2BV2iPn%2FqYnQg5iElM1ZJHcLCJg%3D%3D&&app_pvid=59590_11.132.118.96_605_1582515022334&ptl=floorId:2836;app_pvid:59590_11.132.118.96_605_1582515022334;tpp_pvid:100_11.30.123.20_1481_9201582515022338174&xId=c0crGenktRmROezy6mVjk2tkL6pBkx3RuvHhCTn1sxhh9c5Bemrp63vRaLKa4vdpe0BBiHgDc22Ryyf3KWZEtzTVQ8B2S5Q7rLAjLFdXZDp&union_lens=lensId%3AMAPI%401582515022%400b847660_0e44_170753eea66_534d%4001
商品标题:活动款 新款心机半身裙时尚白领职场女装气质女神范设计感裙子,淘口令:¥l99o1fCeZNz¥优惠券://uland.taobao.com/coupon/edetail?e=gqNTkEONPWgNfLV8niU3RwXoB%2BDaBK5LQS0Flu%2FfbSpinP2GYChM67sPlpg2KVNfy5FOJP2gSFX%2FjE4MyFlOrHFDcPSNdzWLDtf%2Fyr23ZRp1zem6Kf1rlAtVeEzODlKs3JuHcTa5p9m6tM0eJGwHxb87ItztnZWlj1adrxMUuzq3GXpSbfs48vduHvXiCpYSKHGda776GF1YpV%2Fcc5dWNjF1r6%2FoG4NLSB9Oxyt7%2BcDNa4fuEICbKf865raRWOux&&app_pvid=59590_11.132.118.96_605_1582515022334&ptl=floorId:2836;app_pvid:59590_11.132.118.96_605_1582515022334;tpp_pvid:100_11.30.123.20_1481_9201582515022338174&xId=3UATnw13EMWI6QCyyoML3kEc8yfihWrw0ezgU4DVKmLKSyMz9dxTAlV7us1RXMvGy9btjpTbRsUTwqqb753fwgXduF1IeDF314AuWix3vC3p&union_lens=lensId%3AMAPI%401582515022%400b847660_0e44_170753eea66_534e%4001
商品标题:2173欧美新款时尚女装甜美名媛气质性感吊带蕾丝镂空连衣裙长裙潮,淘口令:¥TMr91fC3oK7¥优惠券://uland.taobao.com/coupon/edetail?e=afRTubPXU%2BoNfLV8niU3RwXoB%2BDaBK5LQS0Flu%2FfbSpinP2GYChM67sPlpg2KVNfy5FOJP2gSFVQCqjK7rC3piPyd1nkAnhaw2nNNXDKnyAGE4aWiv7ONXkjwczsXZY1gAwATl4i%2BdeEMoJioP6QwrxjWroxFX74R6m7bMceg6k8Clx5mXPEKiPyd1nkAnhaQtyPk5ZwuRwXaXMZmmPfiArE199RXvLxPiJ4fBVetI3iINPY4XmmYKJ7%2BkHL3AEW&&app_pvid=59590_11.132.118.96_605_1582515022334&ptl=floorId:2836;app_pvid:59590_11.132.118.96_605_1582515022334;tpp_pvid:100_11.30.123.20_1481_9201582515022338174&xId=3fyWZOrumdTFGaelKi6s8DLPwOnLUY1ivwxnLTcSUZz4Xxqht6M2P0xCs37hhFtQL1Bt2iQpWIM6W9sHvIDUCFbYoYFs8ckj90bLiouu8TI&union_lens=lensId%3AMAPI%401582515022%400b847660_0e44_170753eea66_534f%4001
至此,我们成功获取到了带优惠券的、带推广链接的、带淘口令的商品信息。
如有疑问,请您评论,如有帮助,请您点赞????????????!
古人云:贵有恒,何必三更起五更眠;最无益,只怕一日曝十日寒。
古人云:如果不想在世界上虚度一生,那就要学习一辈子。
古人云:只要愿意学习,就一定能学会。
古人云:越学习,越发现自己得无知。
古人云:无贵无贱,无长无少,道之所存,师之所存也。