文档

接口版本 1.1

本文档介绍如何注册、配置和开发应用,以便成功使用我们的 API

创建应用

为了使您的应用能够访问我们的 API,您必须使用 应用仪表板. 注册会创建一个应用 ID,让我们知道你是谁,帮助我们区分你的应用与其他应用.

  1. 您将需要创建一个新应用程序 创建新应用
  2. 创建应用程序后,您将获得您的 app_idapp_secret
登录方式

使用系统登录是人们创建帐户和登录应用程序的一种快速便捷的方式。 我们的“登录方式”系统支持两种方案,即身份认证和请求访问人员数据的权限。您可以使用“登录方式”系统仅进行身份认证或同时进行身份认证和数据访问.

  1. 启动 OAuth 登录过程,您需要像这样为您的应用程序使用链接:
    <a href="https://toutiao6.com/api/oauth?app_id=YOUR_APP_ID">Log in With Hot Community</a>

    用户将被重定向到如下所示的登录方式页面

  2. 用户获得应用后,用户将被重定向到你的应用重定向 URL,内容如下: auth_key 喜欢这个:
    https://mydomain.com/my_redirect_url.php?auth_key=AUTH_KEY
    auth_key 仅对一次性使用有效,因此一旦使用,您将无法再次使用它并生成新代码,您需要再次将用户重定向到使用链接登录.
访问令牌

获得应用的用户批准后,“登录方式”窗口并返回 auth_key 这意味着现在您已准备好从我们的 API 检索数据并开始此过程,您需要授权您的应用程序并获得 access_token 您可以按照我们的步骤了解如何获取它.

  1. 若要获取访问令牌,请向以下终结点发出 HTTP GET 请求,如下所示:
    <?php
    
    $app_id = "YOUR_APP_ID"; // your app id
    $app_secret = "YOUR_APP_SECRET"; // your app secret
    $auth_key = $_GET['auth_key']; // the returned auth key from previous step
    
    // Prepare the POST data
    $postData = [
      'app_id' => $app_id,
      'app_secret' => $app_secret,
      'auth_key' => $auth_key
    ];
    
    // Initialize cURL
    $ch = curl_init('https://toutiao6.com/api/authorize');
    
    // Set cURL options for POST
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
    
    // Execute request
    $response = curl_exec($ch);
    
    // Check for cURL errors
    if (curl_errno($ch)) {
      die('cURL error: ' . curl_error($ch));
    }
    
    curl_close($ch);
    
    // Decode the JSON response
    $json = json_decode($response, true);
    
    // Use the access token if available
    if (!empty($json['access_token'])) {
      $access_token = $json['access_token']; // your access token
    }
    ?>
    
    access_token 仅有效 1 小时,因此一旦无效,您将需要通过将用户重定向到使用链接登录来生成新的.
APIS

一旦你得到你的 access_token 现在,您可以通过HTTP GET请求从我们的系统中检索信息,该请求支持以下参数:

端点 产品描述
api/get_user_info 获取用户信息

您可以像这样检索用户信息

            if(!empty($json['access_token'])) {
                $access_token = $json['access_token']; // your access token
                $get = file_get_contents("https://toutiao6.com/api/get_user_info?access_token=$access_token");
            }
				

结果将是:

            {
              "user_info": {
              "user_id": "",
              "user_name": "",
              "user_email": "",
              "user_firstname": "",
              "user_lastname": "",
              "user_gender": "",
              "user_birthdate": "",
              "user_picture": "",
              "user_cover": "",
              "user_registered": "",
              "user_verified": "",
              "user_relationship": "",
              "user_biography": "",
              "user_website": ""
              }
            }
				
Hot Community https://toutiao6.com