Table of Contents
Reply content:
Home Backend Development PHP Tutorial javascript - How to use Baidu's API? Please give me the answer

javascript - How to use Baidu's API? Please give me the answer

Oct 10, 2016 am 11:56 AM
api html html5 javascript php

api store’s WeChat popular selection api

<code>接口地址 :http://apis.baidu.com/txapi/weixin/wxhot
请求方法 :GET
请求参数(header) :
参数名    类型    必填    参数位置    描述    默认值
apikey
string    是    header    
API密钥
您自己的apikey
请求参数(urlParam) :
参数名    类型    必填    参数位置    描述    默认值
num
number    是    urlParam    
文章返回数量
10
rand
number    否    urlParam    
是否随机,1表示随机
1
word
string    否    urlParam    
检索关键词
盗墓笔记
page
number    否    urlParam    
翻页,输出数量跟随num参数
1
src
string    否    urlParam    
指定文章来源
人民日报

请求示例 :
curl示例php示例python示例java示例C#示例ObjectC示例Swift示例

1
<?php
2
    $ch = curl_init();
3
    $url = 'http://apis.baidu.com/txapi/weixin/wxhot?num=10&rand=1&word=%E7%9B%97%E5%A2%93%E7%AC%94%E8%AE%B0&page=1&src=%E4%BA%BA%E6%B0%91%E6%97%A5%E6%8A%A5';
4
    $header = array(
5
        'apikey: 您自己的apikey',
6
    );
7
    // 添加apikey到header
8
    curl_setopt($ch, CURLOPT_HTTPHEADER  , $header);
9
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
10
    // 执行HTTP请求
11
    curl_setopt($ch , CURLOPT_URL , $url);
12
    $res = curl_exec($ch);
13
​
14
    var_dump(json_decode($res));
15
?></code>
Copy after login
Copy after login
<code>JSON返回示例 :
{
    "code": 200,   //返回状态码
    "msg": "success",  //返回状态消息
    "newslist": [
        {
            "ctime": "2016-03-31",  //文章发布时间
            "title": "奇虎360宣布通过私有化决议",  //文字标题
            "description": "互联网头条",  //来源及描述
            "picUrl": "http://t1.qpic.cn/mblogpic/f01a972dbcc1060fd456/2000", //文章插图,若空为默认
            "url": "http://mp.weixin.qq.com/s?__biz=MjM5OTMyODA2MA==&idx=1&mid=402594468&sn=5cd644536b472a283cc1d3f5124a0cab"
        },  //文章URL
        {
            "ctime": "2016-03-31",
            "title": "小本生意做什么挣钱十七大小本生意推荐",
            "description": "创业最前线",
            "picUrl": "http://zxpic.gtimg.com/infonew/0/wechat_pics_-4225297.jpg/640",
            "url": "http://mp.weixin.qq.com/s?__biz=MzA3NjgzNDUwMQ==&idx=2&mid=401864059&sn=cfa082e38ba38c7e673b1ce0a075faee"
        },
        {
            "ctime": "2016-03-31",
            "title": "当穷游从线上社区向线下旅游服务提供者转身,创业不如就忘了“大平台”这件事吧",
            "description": "中国旅讯",
            "picUrl": "http://zxpic.gtimg.com/infonew/0/wechat_pics_-4218551.jpg/640",
            "url": "http://mp.weixin.qq.com/s?__biz=MzA5MzQyMzQyMw==&idx=3&mid=402488438&sn=88f2d7e415e6d18dafccaa8da549edb6"
        },
        {
            "ctime": "2016-03-31",
            "title": "等我们老了,就去经营这样一家小店",
            "description": "慢时间",
            "picUrl": "http://zxpic.gtimg.com/infonew/0/wechat_pics_-4225311.jpg/640",
            "url": "http://mp.weixin.qq.com/s?__biz=MjM5NTIxNTU0MA==&idx=1&mid=405728106&sn=b8ac94b83aa92eea54acf75eff89c657"
        },
        {
            "ctime": "2016-03-31",
            "title": "曝光失业女子利用微信月均收入过万,原因居然是这个?",
            "description": "那些路过心上的句子",
            "picUrl": "http://zxpic.gtimg.com/infonew/0/wechat_pics_-4116605.jpg/640",
            "url": "http://mp.weixin.qq.com/s?__biz=MjM5MTg3OTAzNg==&idx=1&mid=402804635&sn=172aa8f7bf0f8078ade644f46722c561"
        },
        {
            "ctime": "2016-03-31",
            "title": "什麼人生活在一個單向的世界?",
            "description": "今天文学",
            "picUrl": "http://zxpic.gtimg.com/infonew/0/wechat_pics_-4082011.jpg/640",
            "url": "http://mp.weixin.qq.com/s?__biz=MjM5ODQxODMyMQ==&idx=1&mid=420440897&sn=cb4b009440b6a9d954bff2a622344e8d"
        },
        {
            "ctime": "2016-03-31",
            "title": "这些事,足够让我们相信爱情",
            "description": "女生心理学",
            "picUrl": "http://zxpic.gtimg.com/infonew/0/wechat_pics_-4225315.jpg/640",
            "url": "http://mp.weixin.qq.com/s?__biz=MzA3NjM5NDIyMw==&idx=1&mid=401870610&sn=1baf92ad1bb1b9f575027473754551f9"
        },
        {
            "ctime": "2016-03-31",
            "title": "少女们,为什么你们总爱翻白眼?",
            "description": "青年文摘",
            "picUrl": "http://zxpic.gtimg.com/infonew/0/wechat_pics_-4225320.jpg/640",
            "url": "http://mp.weixin.qq.com/s?__biz=MzA5ODEzMTIxOA==&idx=4&mid=405169046&sn=8ea51ec94fcd5d9bed6d1df0d0bf889f"
        },
        {
            "ctime": "2016-03-31",
            "title": "总说韩国艺人来中国捞金,先看完这些再说吧",
            "description": "RunningMan",
            "picUrl": "http://zxpic.gtimg.com/infonew/0/wechat_pics_-4225344.jpg/640",
            "url": "http://mp.weixin.qq.com/s?__biz=MzA3NDcwNzUxMw==&idx=4&mid=403101020&sn=5a9fa497df693b768637faf85f2b6449"
        },
        {
            "ctime": "2016-03-31",
            "title": "宋仲基宋慧乔频传绯闻宋仲基蛮享受的",
            "description": "韩国新网",
            "picUrl": "http://zxpic.gtimg.com/infonew/0/wechat_pics_-4225352.jpg/640",
            "url": "http://mp.weixin.qq.com/s?__biz=MjM5MDAzNjYwMA==&idx=4&mid=403617618&sn=3446bb057607d2daf2e3123f837fa24d"
        }
    ]
}</code>
Copy after login
Copy after login

How can I put the returned content and images on the web page? Please give me some answers, I'm a newbie

Reply content:

api store’s WeChat popular selection api

<code>接口地址 :http://apis.baidu.com/txapi/weixin/wxhot
请求方法 :GET
请求参数(header) :
参数名    类型    必填    参数位置    描述    默认值
apikey
string    是    header    
API密钥
您自己的apikey
请求参数(urlParam) :
参数名    类型    必填    参数位置    描述    默认值
num
number    是    urlParam    
文章返回数量
10
rand
number    否    urlParam    
是否随机,1表示随机
1
word
string    否    urlParam    
检索关键词
盗墓笔记
page
number    否    urlParam    
翻页,输出数量跟随num参数
1
src
string    否    urlParam    
指定文章来源
人民日报

请求示例 :
curl示例php示例python示例java示例C#示例ObjectC示例Swift示例

1
<?php
2
    $ch = curl_init();
3
    $url = 'http://apis.baidu.com/txapi/weixin/wxhot?num=10&rand=1&word=%E7%9B%97%E5%A2%93%E7%AC%94%E8%AE%B0&page=1&src=%E4%BA%BA%E6%B0%91%E6%97%A5%E6%8A%A5';
4
    $header = array(
5
        'apikey: 您自己的apikey',
6
    );
7
    // 添加apikey到header
8
    curl_setopt($ch, CURLOPT_HTTPHEADER  , $header);
9
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
10
    // 执行HTTP请求
11
    curl_setopt($ch , CURLOPT_URL , $url);
12
    $res = curl_exec($ch);
13
​
14
    var_dump(json_decode($res));
15
?></code>
Copy after login
Copy after login
<code>JSON返回示例 :
{
    "code": 200,   //返回状态码
    "msg": "success",  //返回状态消息
    "newslist": [
        {
            "ctime": "2016-03-31",  //文章发布时间
            "title": "奇虎360宣布通过私有化决议",  //文字标题
            "description": "互联网头条",  //来源及描述
            "picUrl": "http://t1.qpic.cn/mblogpic/f01a972dbcc1060fd456/2000", //文章插图,若空为默认
            "url": "http://mp.weixin.qq.com/s?__biz=MjM5OTMyODA2MA==&idx=1&mid=402594468&sn=5cd644536b472a283cc1d3f5124a0cab"
        },  //文章URL
        {
            "ctime": "2016-03-31",
            "title": "小本生意做什么挣钱十七大小本生意推荐",
            "description": "创业最前线",
            "picUrl": "http://zxpic.gtimg.com/infonew/0/wechat_pics_-4225297.jpg/640",
            "url": "http://mp.weixin.qq.com/s?__biz=MzA3NjgzNDUwMQ==&idx=2&mid=401864059&sn=cfa082e38ba38c7e673b1ce0a075faee"
        },
        {
            "ctime": "2016-03-31",
            "title": "当穷游从线上社区向线下旅游服务提供者转身,创业不如就忘了“大平台”这件事吧",
            "description": "中国旅讯",
            "picUrl": "http://zxpic.gtimg.com/infonew/0/wechat_pics_-4218551.jpg/640",
            "url": "http://mp.weixin.qq.com/s?__biz=MzA5MzQyMzQyMw==&idx=3&mid=402488438&sn=88f2d7e415e6d18dafccaa8da549edb6"
        },
        {
            "ctime": "2016-03-31",
            "title": "等我们老了,就去经营这样一家小店",
            "description": "慢时间",
            "picUrl": "http://zxpic.gtimg.com/infonew/0/wechat_pics_-4225311.jpg/640",
            "url": "http://mp.weixin.qq.com/s?__biz=MjM5NTIxNTU0MA==&idx=1&mid=405728106&sn=b8ac94b83aa92eea54acf75eff89c657"
        },
        {
            "ctime": "2016-03-31",
            "title": "曝光失业女子利用微信月均收入过万,原因居然是这个?",
            "description": "那些路过心上的句子",
            "picUrl": "http://zxpic.gtimg.com/infonew/0/wechat_pics_-4116605.jpg/640",
            "url": "http://mp.weixin.qq.com/s?__biz=MjM5MTg3OTAzNg==&idx=1&mid=402804635&sn=172aa8f7bf0f8078ade644f46722c561"
        },
        {
            "ctime": "2016-03-31",
            "title": "什麼人生活在一個單向的世界?",
            "description": "今天文学",
            "picUrl": "http://zxpic.gtimg.com/infonew/0/wechat_pics_-4082011.jpg/640",
            "url": "http://mp.weixin.qq.com/s?__biz=MjM5ODQxODMyMQ==&idx=1&mid=420440897&sn=cb4b009440b6a9d954bff2a622344e8d"
        },
        {
            "ctime": "2016-03-31",
            "title": "这些事,足够让我们相信爱情",
            "description": "女生心理学",
            "picUrl": "http://zxpic.gtimg.com/infonew/0/wechat_pics_-4225315.jpg/640",
            "url": "http://mp.weixin.qq.com/s?__biz=MzA3NjM5NDIyMw==&idx=1&mid=401870610&sn=1baf92ad1bb1b9f575027473754551f9"
        },
        {
            "ctime": "2016-03-31",
            "title": "少女们,为什么你们总爱翻白眼?",
            "description": "青年文摘",
            "picUrl": "http://zxpic.gtimg.com/infonew/0/wechat_pics_-4225320.jpg/640",
            "url": "http://mp.weixin.qq.com/s?__biz=MzA5ODEzMTIxOA==&idx=4&mid=405169046&sn=8ea51ec94fcd5d9bed6d1df0d0bf889f"
        },
        {
            "ctime": "2016-03-31",
            "title": "总说韩国艺人来中国捞金,先看完这些再说吧",
            "description": "RunningMan",
            "picUrl": "http://zxpic.gtimg.com/infonew/0/wechat_pics_-4225344.jpg/640",
            "url": "http://mp.weixin.qq.com/s?__biz=MzA3NDcwNzUxMw==&idx=4&mid=403101020&sn=5a9fa497df693b768637faf85f2b6449"
        },
        {
            "ctime": "2016-03-31",
            "title": "宋仲基宋慧乔频传绯闻宋仲基蛮享受的",
            "description": "韩国新网",
            "picUrl": "http://zxpic.gtimg.com/infonew/0/wechat_pics_-4225352.jpg/640",
            "url": "http://mp.weixin.qq.com/s?__biz=MjM5MDAzNjYwMA==&idx=4&mid=403617618&sn=3446bb057607d2daf2e3123f837fa24d"
        }
    ]
}</code>
Copy after login
Copy after login

How can I put the returned content and images on the web page? Please give me some answers, I'm a newbie

Just put it directly into the corresponding tag....

What you need to know:

  1. How to send requests in the backend language you know

  2. What is json and how to parse json using your backend language or JavaScript

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Services CakePHP Services Sep 10, 2024 pm 05:26 PM

This chapter deals with the information about the authentication process available in CakePHP.

See all articles