搜索插件、代码仓与 APP 分类

插件详情v0.1.2

twitter_api

一种简单的方法来认证并请求 Twitter API。

近 30 天下载
24
喜欢数
24
Pub 分数
40

安装插件

flutter pub add twitter_api

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

twitter_api 包为 Flutter 应用程序提供了一种简单的方法来认证并交互 Twitter API。它简化了处理 OAuth 1.0a 认证的过程,使开发者能够安全地发起针对推文、用户数据和其他 Twitter 资源的 API 请求。该包设计简洁易用,抽象了复杂的认证流程,并可无缝集成到 Dart 项目中。对于需要实时社交媒体集成或用户互动功能的应用程序,该包尤其有用。

适合场景

  • 获取用户时间线
  • 通过程序发布推文
  • 通过 Twitter 验证用户
  • 集成社交分享功能
  • 构建实时推文流
  • 访问公共 Twitter 数据

主要特点

  • 简单的 OAuth 1.0a 实现
  • 简洁直观的 API 接口
  • 安全的令牌管理
  • 支持读取和写入操作
  • 文档齐全的方法
  • 与 Flutter 应用轻松集成

适合对象

  • 社交媒体应用
  • 内容聚合工具
  • 用户身份验证系统
  • 实时数据流应用
  • 需要 Twitter 集成的应用程序

使用建议

  • 需要正确的 Twitter 开发者账户
  • 仅限 Twitter API v1.1
  • 无内置速率限制处理
  • 需要手动处理错误
  • 依赖外部GitHub仓库
  • 不适用于 Twitter API v2 功能

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Dart Twitter API

A Project that was made to make using the Twitter API from flutter and dart a bit easier.

This package contains a high level functionality for connecting to the Twitter API. Provice the secret and public keys, and then make the request to Twitter. The package will handle all of the authentication. This only works for application authentication. User authentication is not implemented and is not planned for the future.

How to Use

Below is an example of how the package would be used.

import 'package:twitter_api/twitter_api.dart';

// Creating the twitterApi Object with the secret and public keys
// These keys are generated from the twitter developer page
// Dont share the keys with anyone
final _twitterOauth = new twitterApi(
  consumerKey: consumerApiKey,
  consumerSecret: consumerApiSecret,
  token: accessToken,
  tokenSecret: accessTokenSecret
);

// Make the request to twitter
Future twitterRequest = _twitterOauth.getTwitterRequest(
  // Http Method
  "GET", 
  // Endpoint you are trying to reach
  "statuses/user_timeline.json", 
  // The options for the request
  options: {
    "user_id": "19025957",
    "screen_name": "TTCnotices",
    "count": "20",
    "trim_user": "true",
    "tweet_mode": "extended", // Used to prevent truncating tweets
  },
);

// Wait for the future to finish
var res = await twitterRequest;

// Print off the response
print(res.statusCode); 
print(res.body);

Requests

Only application authentication is supported by this package.

There are two different types of paramters that will be needed. Depoendant and Independant

The first type is the independant paramters. These are things that every single request will need, no matter the content you are trying to get. These values include:

  • A consumer API key
  • A consumer API secret key
  • An access token
  • A secret access token

These are the keys that are used to authenticate your request. Make sure they are correctly entered. You should keep these secret and private.

Next are the dependant variables. These are things that depend on the type of request you are trying to make. These values include:

  • method: HTTP Method
    • This is a required parameter of type String
    • GET or POST
  • url: The endpoint you are trying to reach
    • This is a required paramter of type String
    • Some examples on the twitter website include /1.1/ but do not include that when making requests here. That part is already added internally
  • options: The parameters of the request you are trying to make
    • This is an optional paramter of type Map<String, String>
    • These are things like which user you are trying to view, how many tweets you are trying to get, whether to strip user info from the response or not
    • The full list of these parameters can be found at the Twitter Developer Website

Response

Below is a truncated example of the data that is returned from the above example. It is initially sent as a string and needs to be parsed to get to this state.

To convert it from a string to a List of Maps:

import 'dart:convert';
var tweets = json.decode(res.body);

The data that comes out of the request after converting it:

var resBody = [
  {
    "created_at": "Wed Oct 02 23:28:13 +0000 2019",
    "id": 1179538608740556800,
    "id_str": "1179538608740556800",
    "full_text":
        "52 Lawrence West and 952 Lawrence West Express: Detour westbound via Culford Rd, Maple Leaf Dr and Jane St due to emergency sewer repair.\nhttps:\/\/t.co\/jPSDy5TW8Q",
    "truncated": false,
    "display_text_range": [0, 161],
    "entities": {
      "hashtags": [],
      "symbols": [],
      "user_mentions": [],
      "urls": [
        {
          "url": "https:\/\/t.co\/jPSDy5TW8Q",
          "expanded_url":
              "https:\/\/twitter.com\/TTCnotices\/status\/1179537904022016000",
          "display_url": "twitter.com\/TTCnotices\/sta\u2026",
          "indices": [138, 161]
        }
      ]
    },
    "source":
        "\u003ca href=\"https:\/\/www.hootsuite.com\" rel=\"nofollow\"\u003eHootsuite Inc.\u003c\/a\u003e",
    "in_reply_to_status_id": null,
    "in_reply_to_status_id_str": null,
    "in_reply_to_user_id": null,
    "in_reply_to_user_id_str": null,
    "in_reply_to_screen_name": null,
    "user": {"id": 19025957, "id_str": "19025957"},
    "geo": null,
    "coordinates": null,
    "place": null,
    "contributors": null,
    "is_quote_status": true,
    "quoted_status_id": 1179537904022016000,
    "quoted_status_id_str": "1179537904022016000",
    "quoted_status_permalink": {
      "url": "https:\/\/t.co\/jPSDy5TW8Q",
      "expanded":
          "https:\/\/twitter.com\/TTCnotices\/status\/1179537904022016000",
      "display": "twitter.com\/TTCnotices\/sta\u2026"
    },
    "quoted_status": {
      "created_at": "Wed Oct 02 23:25:25 +0000 2019",
      "id": 1179537904022016000,
      "id_str": "1179537904022016000",
      "full_text":
          "52 Lawrence West and 952 Lawrence West Express: Detour westbound via Culford Rd, Maple Leaf Dr and Jane St due to a collision.",
      "truncated": false,
      "display_text_range": [0, 126],
      "entities": {
        "hashtags": [],
        "symbols": [],
        "user_mentions": [],
        "urls": []
      },
      "source":
          "\u003ca href=\"https:\/\/www.hootsuite.com\" rel=\"nofollow\"\u003eHootsuite Inc.\u003c\/a\u003e",
      "in_reply_to_status_id": null,
      "in_reply_to_status_id_str": null,
      "in_reply_to_user_id": null,
      "in_reply_to_user_id_str": null,
      "in_reply_to_screen_name": null,
      "user": {"id": 19025957, "id_str": "19025957"},
      "geo": null,
      "coordinates": null,
      "place": null,
      "contributors": null,
      "is_quote_status": false,
      "retweet_count": 1,
      "favorite_count": 1,
      "favorited": false,
      "retweeted": false,
      "lang": "en"
    },
    "retweet_count": 0,
    "favorite_count": 0,
    "favorited": false,
    "retweeted": false,
    "possibly_sensitive": false,
    "lang": "en"
  },
]

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目

暂无相关数据。