推特开发者账号申请失败【推特开发者文档系列7】——通过API接口发布、检索推文

本系列是对推特开发者文档进行的翻译,以便帮助开发人员使用API接口,难免有些地方存在不足,还请谅解。

关于推特开发者账号 elevated academic 请看此贴:

推特开发者账号申请权限

搜索微信公众号 twitterDeveloper 获得帮助


Post, retrieve, and engage with Tweets

通过以下API接口可以通过编程的方式创建、检索和删除Tweets、Retweets和Like:

Tweets(发推文)Retweets(转推)Likes(点赞)
POST statuses/update
POST statuses/destroy/:id
GET statuses/show/:id
GET statuses/oembed
GET statuses/lookup
POST statuses/retweet/:id
POST statuses/unretweet/:id
GET statuses/retweets/:id
GET statuses/retweets_of_me
GET statuses/retweeters/ids
POST favorites/create/:id
POST favorites/destroy/:id
GET favorites/list

有关更多详细信息,请参阅 API文档部分中的各个端口信息 。


示例

通过API发推文

对于每次更新尝试,都会将更新文本与验证用户的最新推文进行比较。 任何可能导致重复的尝试都将被阻止,从而导致403错误。 用户不能连续两次提交相同的状态。(一次POST有且仅生效一次)

尽管不受API的速率限制,但用户一次只能创建的Tweets数量受到限制。 如果用户发布的更新数量达到当前允许的限制,则此方法将返回HTTP 403错误。

关于地理位置

  • 如果为用户提供的geo_enabled为false(此设置是所有用户的默认设置,除非用户已在其设置中启用地理定位),更新中的所有地理标记参数都将被忽略。
  • lat跟踪传递给小数点分隔符后的位数(最多8位),以便当lat在状态对象中返回时,小数点分隔符后将具有相同的位数。
  • 使用小数点作为纬度和经度的分隔符(而不是小数逗号)
  • 对于JSON,响应主要使用GeoJSON中描述的约定。 但是,Twitter渲染的geo对象坐标与GeoJSON规范相反。 GeoJSON指定了一个经度然后是一个纬度,而Twitter则将其表示为一个纬度然后是经度:“ geo”:{“ type”:“ Point”,“ coordinates”:[37.78217,-122.40062]}
  • coordinates对象将替换geo对象(尚未设置geo对象的弃用日期)-区别在于,coordinates对象(以JSON)现在可以在GeoJSON中正确呈现。
  • 如果将place_id传递到状态更新中,则该位置将附加到状态中。 如果未明确提供place_id,但提供了纬度和经度,则API会尝试通过调用geo / reverse_geocode隐式提供位置。
  • 用户可以通过用户设置页面从其所有推文中删除所有地理标签。 目前,尚无从单个Tweet移除地理标签的方法。

接口url

https://api.twitter.com/1.1/statuses/update.json

资源信息

响应格式Json
是否需要认证是(仅限用户上下文)
频率限制
请求/3小时窗口期每位用户300 ;每个应用300

注:每3小时300次的限制是POST statuses/retweet/:id :端点数目的总和。 您在3个小时内只能发布300条Tweets或Retweets。

参数

名称是否必要描述默认值示例
status需要状态更新的文本。 URL根据需要进行编码。 t.co链接换行将影响字符计数。
in_reply_to_status_id可选更新正在答复的现有状态的ID。注意:此参数将被忽略,除非状态文本中提到此参数引用的Tweet的作者。因此,您必须在更新中包含@username,其中username是引用Tweet的作者。
auto_populate_reply_metadata可选如果设置为true并与in_reply_to_status_id一起使用,则将从原始Tweet中查找前导@提到,并从此处添加到新Tweet中。随着回复链的增长,这将在扩展Tweet的元数据中追加@insertions,直到达到@insertions的限制。如果原始推文被删除,回复将失败。falsetrue
exclude_reply_user_ids可选当与auto_populate_reply_元数据一起使用时,一个逗号分隔的用户id列表将从服务器上删除,该列表将在扩展的Tweet上显示@references前缀。请注意,不能删除前导的@notice,因为它会破坏in reply to status id语义。尝试删除它将被忽略。786491,54931584
lat可选此Tweet所指位置的纬度。此参数将被忽略,除非它在-90.0到+90.0(北为正)范围内。如果没有相应的long参数,也将忽略它。37.7821120598956
long可选此Tweet所指位置的经度。经度的有效范围是-180.0到+180.0(东为正)。如果超出该范围,如果不是数字,如果启用了地理坐标,或者没有相应的lat参数,则将忽略此参数。-122.400612831116
place_id可选世界上的一个地方df51dec6f4ee2b2c
display_coordinates可选是否在发送推文的确切坐标上放置图钉。true
trim_user可选当设置为true、t或1时,响应将包含仅包含作者ID的用户对象。省略此参数可接收完整的用户对象。falsetrue
enable_dmcommands可选设置为true时,启用快捷方式命令,将直接消息作为状态文本的一部分发送给用户。如果设置为false,则禁用此行为,并在发布的状态文本中包含任何前导字符falsetrue
fail_dmcommands可选设置为true时,使以shortcode命令开头的任何状态文本都返回API错误。 设置为false时,允许在状态文本中发送简码命令并由API进行操作。truefalse
card_uri可选使用来自任何广告卡响应的card-uri值将广告卡与Tweet关联。card://853503245793641682
attachment_url可选为了使URL不计入扩展Tweet的状态正文中,请提供一个URL作为Tweet附件。此URL必须是Tweet永久链接或直接消息深度链接。任意的非Twitter url必须保留在状态文本中。传递给attachment_url参数的url与Tweet permalink或Direct Message deep link不匹配,将在创建Tweet时失败并导致异常。https://twitter.com/andypiper/status/903615884664725505
media_ids可选与Tweet关联的media_id的逗号分隔列表。 您最多可以在Tweet中包含4张照片或1个GIF动画或1个视频。 有关上传媒体的更多详细信息,请参见上传媒体。471592142565957632
possibly_sensitive可选如果上载的Tweet媒体可能被视为敏感内容(如裸体或医疗程序),则必须将此值设置为true。有关更多内容,请参见媒体设置和最佳实践。falsetrue

请求示例

要获取生成的oauth_nonce,oauth_token和oauth_signature,可以使用REST工具,例如Insomnia或Postman。

curl -XPOST 
  --url 'https://api.twitter.com/1.1/statuses/update.json?status=hello' 
  --header 'authorization: OAuth
  oauth_consumer_key="oauth_customer_key",
  oauth_nonce="generated_oauth_nonce",
  oauth_signature="generated_oauth_signature",
  oauth_signature_method="HMAC-SHA1",
  oauth_timestamp="generated_timestamp",
  oauth_token="oauth_token",
  oauth_version="1.0"'

很多人想把状态从“hello”改成其他的。

您还可以使用任何其他想要的OAuth帮助程序库,比如twurl。
$ twurl -d 'status=Test tweet using the POST statuses/update endpoint' /1.1/statuses/update.json

响应例子

请求成功后,将返回以下内容:

{
  "created_at": "Wed Oct 10 20:19:24 +0000 2018",
  "id": 1050118621198921700,
  "id_str": "1050118621198921728",
  "text": "To make room for more expression, we will now count all emojis as equal—including those with gender‍‍‍ ‍‍and skin t… https://t.co/MkGjXf9aXm",
  "source": "<a href="http://twitter.com" rel="nofollow">Twitter Web Client</a>",
  "truncated": true,
  "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": 6253282,
    "id_str": "6253282",
    "name": "Twitter API",
    "screen_name": "TwitterAPI",
    "location": "San Francisco, CA",
    "url": "https://developer.twitter.com",
    "description": "The Real Twitter API. Tweets about API changes, service issues and our Developer Platform. Don't get an answer? It's on my website.",
    "translator_type": "null",
    "derived": {
      "locations": [
        {
          "country": "United States",
          "country_code": "US",
          "locality": "San Francisco",
          "region": "California",
          "sub_region": "San Francisco County",
          "full_name": "San Francisco, California, United States",
          "geo": {
            "coordinates": [
              -122.41942,
              37.77493
            ],
            "type": "point"
          }
        }
      ]
    },
    "protected": false,
    "verified": true,
    "followers_count": 6172196,
    "friends_count": 12,
    "listed_count": 13003,
    "favourites_count": 31,
    "statuses_count": 3650,
    "created_at": "Wed May 23 06:01:13 +0000 2007",
    "utc_offset": null,
    "time_zone": null,
    "geo_enabled": false,
    "lang": "en",
    "contributors_enabled": false,
    "is_translator": null,
    "profile_background_color": "null",
    "profile_background_image_url": "null",
    "profile_background_image_url_https": "null",
    "profile_background_tile": null,
    "profile_link_color": "null",
    "profile_sidebar_border_color": "null",
    "profile_sidebar_fill_color": "null",
    "profile_text_color": "null",
    "profile_use_background_image": null,
    "profile_image_url": "null",
    "profile_image_url_https": "https://pbs.twimg.com/profile_images/942858479592554497/BbazLO9L_normal.jpg",
    "profile_banner_url": "https://pbs.twimg.com/profile_banners/6253282/1497491515",
    "default_profile": false,
    "default_profile_image": false,
    "following": null,
    "follow_request_sent": null,
    "notifications": null
  },
  "geo": null,
  "coordinates": null,
  "place": null,
  "contributors": null,
  "is_quote_status": false,
  "extended_tweet": {
    "full_text": "To make room for more expression, we will now count all emojis as equal—including those with gender‍‍‍ ‍‍and skin tone modifiers 👍🏻👍🏽👍🏿. This is now reflected in Twitter-Text, our Open Source library. nnUsing Twitter-Text? See the forum post for detail: https://t.co/Nx1XZmRCXA",
    "display_text_range": [
      0,
      277
    ],
    "entities": {
      "hashtags": [],
      "urls": [
        {
          "url": "https://t.co/Nx1XZmRCXA",
          "expanded_url": "https://twittercommunity.com/t/new-update-to-the-twitter-text-library-emoji-character-count/114607",
          "display_url": "twittercommunity.com/t/new-update-t…",
          "unwound": {
            "url": "https://twittercommunity.com/t/new-update-to-the-twitter-text-library-emoji-character-count/114607",
            "status": 200,
            "title": "New update to the Twitter-Text library: Emoji character count",
            "description": "Over the years, we have made several updates to the way that people can communicate on Twitter. One of the more notable changes made last year was to increase the number of characters per Tweet from 140 to 280 characters. Today, we continue to expand people’s ability to express themselves by announcing a change to the way that we count emojis. Due to the differences in the way written text and emojis are encoded, many emojis (including emojis where you can apply gender and skin tone) have count..."
          },
          "indices": [
            254,
            277
          ]
        }
      ],
      "user_mentions": [],
      "symbols": []
    }
  },
  "quote_count": 0,
  "reply_count": 0,
  "retweet_count": 0,
  "favorite_count": 0,
  "entities": {
    "hashtags": [],
    "urls": [
      {
        "url": "https://t.co/MkGjXf9aXm",
        "expanded_url": "https://twitter.com/i/web/status/1050118621198921728",
        "display_url": "twitter.com/i/web/status/1…",
        "indices": [
          117,
          140
        ]
      }
    ],
    "user_mentions": [],
    "symbols": []
  },
  "favorited": false,
  "retweeted": false,
  "possibly_sensitive": false,
  "filter_level": "low",
  "lang": "en"
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值