zoukankan      html  css  js  c++  java
  • web端--斗图Tenor api 接入

    项目中有用到斗图表情,需接入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: url
    12 
    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: searchUrl
    20 
    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 }

    Tenor api地址: https://tenor.com/gifapi/documentation#quickstart

  • 相关阅读:
    hdu 4685(强连通分量+二分图的完美匹配)
    图的连通性问题
    poj 1904(强连通分量+完美匹配)
    poj 2186 "Popular Cows"(强连通分量入门题)
    poj 1236(强连通分量分解模板题)
    EOJ2018.10 月赛
    21.Merge Two Sorted Lists
    20.Valid Parentheses
    19.Remove Nth Node From End of List
    18.4Sum
  • 原文地址:https://www.cnblogs.com/CaktyRiven/p/9248185.html
Copyright © 2011-2022 走看看