博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
web端--斗图Tenor api 接入
阅读量:7103 次
发布时间:2019-06-28

本文共 1485 字,大约阅读时间需要 4 分钟。

项目中有用到斗图表情,需接入Tenor斗图库,

此仅做记录,便于今后回忆,

如能给你程序之旅带来些许帮助,

不胜荣幸,

大神请绕道,

废话不多说,

1、获取秘钥 或使用提供的秘钥

1 var apikey = 'LIVDSRZULELA';

2、通过给定秘钥ajax请求返回指定anon_id

1 // 获取tenor anonid 2  3 getAnonId: function () { 4  5     var url = 'https://api.tenor.com/v1/anonid?key=' + 'LIVDSRZULELA'; 6  7     this.$ajax({ 8  9         method: 'GET',10 11         url: url12 13     }).then(res => {14 15         this.anonid = res.data.anon_id;16 17     });18 19 },

3、通过给定的anon_id,请求返回gif数据

p(searchTerm )—搜索关键字

lmt – 获取的gif数组数量

1 // ajax加载gif方法 2  3 getTenorGif: function (searchText, num) { 4  5     var searchResultList = []; 6  7     var apikey = 'LIVDSRZULELA'; 8  9     var lmt = num;10 11     var searchTerm = searchText;12 13     var searchUrl = 'https://api.tenor.com/v1/search?tag=' + searchTerm + '&key=' + apikey + '&limit=' + lmt + '&anon_id=' + this.anonid;14 15     this.$ajax({16 17         method: 'GET',18 19         url: searchUrl20 21     }).then(response => {22 23         // 处理获取的数据24 25         for (var i = 0; i < response.data.results.length; i++) {26 27             for (var j = 0; j < response.data.results[i].media.length; j++) {28 29                 var json = {nanogif: response.data.results[i].media[j].nanogif.url, tinygif: response.data.results[i].media[j].tinygif.url};30 31                 searchResultList.push(json);32 33             };34 35         };36 37         this.searchResult = searchResultList;38 39     });40 41 }

 

转载于:https://www.cnblogs.com/CaktyRiven/p/9248185.html

你可能感兴趣的文章