Open API documentation on Twitter
Twitter opens some application interfaces through APIS. This document describes the interfaces currently open to Twitter and provides technical and documentation services for developers who want to develop tools or applications based on Twitter service extensions.
Authentication
Except for some APIs (for example, public timeline), all API methods must require user authentication, and all responses must be related to authenticated users. For example, if you try to obtain user information that is set to private and not your friend, the system will return a failure status.
Twitter currently only supportsHTTP Basic AuthenticationVerification mechanism. When usingHTTP Basic AuthenticationUse the "user name" you registered on Twitter as part of the "user name" of the session or cookie.
Multi-State [restfull] result Transmission
The Twitter API strives to return data in the corresponding format based on the user's specific request. You can find that the API we provide has an important convenience. by simply changing the file Suffix in the URI, you can obtain the format of the returned result. This document describes the formats available for each method.
Twitter currently supports the following four data return formats:XML,JSON,RSSAnd atom. You can use different request methods to specify different returned results for each request.
Parameters
Some APIs accept optional and required parameters. When the parameters are available, we will mention these parameters in the following documents. Note: When sending a complex string, be sure to encode the string in UTF-8 format and then perform URL encoding again (encode ).
HTTPRequest
Unless otherwise specified, the POST method is used when Twitter's open API is called through http get, and information must be submitted or private messages must be sent.
The following describes the format of the information returned by the API. Some APIs return information related to the "content" of the user request, some information related to the "HTTP header information" sent by the client will be returned. For example, most methods that support the since parameter are also interested in the HTTP header if-modified-since. It should be noted that when some behaviors can be controlled by parameters and HTTP headers, values set by parameters are preferentially accepted.
When a request returns data, the returned data is encoded in the UTF-8 format and some external symbols are encoded in the HTML Entity (& # number; or & text) format.
Restrictions
Each client can request a maximum of 150 requests per hour.
HTTPStatus Code
The Twitter API returns an appropriate HTTP status for each request. For example, if you request a non-existent user information, the API returns 404 Not found. If a request is not authenticated and authorized, the API returns the 401 not authorized status.
Use APIEasy way
If your system hasCurlYou already have a very powerful tool for using Weibo APIs. The following example uses curl, which is very simple:
Access public_timeline: curl without authorizationHttp://api.twitter.com/statuses/public_timeline.xml
Get a friend's timeline, using authentication: curl-u Email: Password http://api.twitter.com/statuses/friends_timeline.xml
Only obtain the header information: curl -- head Email: PasswordHttp://api.twitter.com/statuses/friends_timeline.json
User status
Statuses/public_timeline
Returns the last 20 messages of the user (which must have a custom profile picture) without private information. This method does not require identity authentication.
Access address:Http://api.twitter.com/statuses/public_timeline.format
Supported format):XML, JSON, RSS, Atom
Parameter List:
None.
Statuses/friends_timeline
Returns the latest 20 updated authenticated users and their friends in the last 24 hours.
Access address:Http://api.twitter.com/statuses/friends_timeline.format
Supported formats(Format): XML, JSON, RSS, Atom
Parameter List:
Since_id: an optional parameter (Weibo information Id). Only Weibo information content with a higher ID than since_id (later than since_id) is returned.
Example: http://api.twitter.com/statuses/friends_timeline.xml? Since_id = 1, 12345
Max_id: an optional parameter (Weibo information Id). The returned Weibo information content with the id not greater than max_id.
Example: http://api.twitter.com/statuses/friends_timeline.xml? Max_id = 54321
Count: Optional. the maximum number of records returned each time. The value cannot exceed 200. The default value is 20.
Example: http://api.twitter.com/statuses/friends_timeline.xml? Count = 5
Page: optional parameter. Page number of the returned result. Note: There are paging restrictions. Based on the number of objects posted by the user, a maximum of 1,000 entries of the latest Weibo page are usually returned. The default value is 1.
Example: http://api.twitter.com/statuses/friends_timeline.xml? Page = 3
Statuses/user_timeline
Return the 20 latest messages updated by the authenticated user within the last 24 hours. Similarly, you can use the useridorname parameter to request the latest message updates from other users. This API can be unauthenticated.
Access address:Http://api.twitter.com/statuses/user_timeline.format
Supported formats(Format): XML, JSON, RSS, Atom
Parameter List:
ID: an optional parameter. Weibo information is returned Based on the specified user UID or Weibo nickname.
Example: http://api.twitter.com/statuses/user_timeline/12345.xml
User_id: optional parameter. User uid, which is used to distinguish a user uid from a microblog nickname. this parameter is used to differentiate user uid from a microblog nickname when the microblog nickname is a number, which leads to ambiguity with the user uid.
Example: http://api.twitter.com/statuses/user_timeline.xml? User_id = 1401881
Screen_name: an optional parameter. Weibo nickname, which is used to distinguish uid from Weibo nickname.
Example: http://api.twitter.com/statuses/user_timeline.xml? Screen_name = 101010
Since_id: an optional parameter (Weibo information Id). Only Weibo information content with a higher ID than since_id (later than since_id) is returned.
Example: http://api.twitter.com/statuses/user_timeline.xml? Since_id = 1, 12345
Max_id: an optional parameter (Weibo information Id). The returned Weibo information content with the id not greater than max_id.
Example: http://api.twitter.com/statuses/user_timeline.xml? Max_id = 54321
Count: Optional. Maximum number of records returned each time. A maximum of 200 records can be returned. The default value is 20.
Example: http://api.twitter.com/statuses/user_timeline.xml? Count = 200
Page: Optional. Return by page. Note: a maximum of 200 page content is returned.
Example: http://api.twitter.com/statuses/user_timeline.xml? Page = 3
Statuses/mentions
Displays 20 recent reply messages to a user (the message prefix is @ username ). This API is only open to authenticated users. The list of reply messages sent to other users is invalid, regardless of whether other users are set to private or not.
Access address: Http://api.twitter.com/statuses/replies.format
Supported formats(Format): XML, JSON, RSS, Atom
Parameter List:
Since_id. optional parameter. The return ID is greater than the value since_id (later than the since_id time.
Example: http://api.twitter.com/statuses/mentions.xml? Since_id = 1, 12345
Max_id. optional parameter. The returned ID is not later than max_id.
Example: http://api.twitter.com/statuses/mentions.xml? Max_id = 54321
Count. optional parameter. Maximum number of records returned each time (that is, the page size), not greater than 200, the default value is 20.
Example: http://api.twitter.com/statuses/mentions.xml? Count = 200
Page. optional parameter. Page number of the returned result. Note: There are paging restrictions.
Example: http://api.twitter.com/statuses/mentions.xml? Page = 3
User message related methods
Statuses/show
Returns a message with the specified ID, which contains the author information.
Access address: Http://api.twitter.com/statuses/show/id.formator
Http://api.twitter.com/statuses/show.format? Id = {ID}
Supported formats(Format): XML, JSON
Parameter List:
Id. Required parameter (Weibo information Id). To obtain the ID of a published microblog, if the ID does not exist, an empty message is returned.
Example: http://api.twitter.com/statuses/show/142277.xml
Statuses/update
The message for updating Authenticated Users must contain the content parameter and must be requested in post mode. If the message succeeds, the current message is returned in the specified format.
Access address:Http://api.twitter.com/statuses/update.format
Supported formats(Format): XML, JSON
Parameter List:
Status. this parameter is required. The Weibo information to be updated. Urlencode is required. The message content contains more than 140 Chinese characters. If it is null, the error 400 is returned.
In_reply_to_status_id. optional parameter, @ ID of the Weibo message to be replied. this parameter is meaningful only when the microblog content starts with @ username.
Lat. Available parameter, latitude, location of the current Weibo posting, valid range:-90.0 to + 90.0, + indicates north latitude. The location is valid only when geo_enabled is set to true.
Long. An optional parameter, longitude. Valid range:-180.0 to + 180.0. + indicates the eastern longitude.
Statuses/destroy
Deletes a message based on the specified ID. The authenticated user must be the message creator.
Access address: Http://api.twitter.com/statuses/destroy/id.format
Supported formats(Format): XML, JSON
Parameter List:
The ID is required. The ID of the message to be deleted, for example:
Http://api.twitter.com/statuses/destroy/12345.json
Or
Http://api.twitter.com/statuses/destroy.xml? Id = 23456
User operation interface
Users/show
To display the extension information of a specified user, you must specify the user ID or display name. The extended information includes the user's page settings and the number of Weibo posts. Therefore, third-party application developers can provide users with appropriate topics based on the information.
Note: This API call request must be sent to a legitimate Weibo user, regardless of the extended information of the user or another user.
Access address: Http://api.twitter.com/users/show.format
Supported formats(Format): XML, JSON
Parameter List:
Id. User UID or Weibo nickname.
Example: http://api.twitter.com/users/show/12345.json or http://api.twitter.com/users/show/bob.xml
User_id. specifies the user uid, which is used to distinguish a user uid from a microblog nickname. This is used to indicate ambiguity, especially when the user account is a number, resulting in ambiguity with the user uid.
Example: http://api.twitter.com/users/show.xml? User_id = 1401881
Screen_name. This parameter specifies the nickname of a Weibo account. It is used to distinguish uid from the nickname of a Weibo account.
Example: http://api.twitter.com/users/show.xml? Screen_name = 101010
Statuses/friends
Return to the authenticated user's friend list, which contains the current Weibo information of each user. This method can also be used to request a list of friends of other users and pass the ID parameter through the method specified below.
Access address: Http://api.twitter.com/statuses/friends.format
Supported formats(Format): XML, JSON
Parameter List:
Id. optional parameter. UID or Weibo nickname to be obtained
Example: http://api.twitter.com/statuses/friends/12345.json
Http://api.twitter.com/statuses/friends/12345.xml
User_id. optional parameter. UID to be obtained
Example: http://api.twitter.com/statuses/friends.xml? User_id = 1401881
Screen_name. optional parameter. Weibo nickname to be obtained
Example: http://api.twitter.com/statuses/friends.xml? Screen_name = 101010
Cursor. optional parameters. A single page can only contain 100 follow lists. To get more, the cursor starts from-1 by default. You can increase or decrease the cursor to get more. If no next page exists, next_cursor returns 0.
Follow list
Example: http://api.twitter.com/statuses/friends/williamlong.xml? Cursor =-1
Example: http://api.twitter.com/statuses/friends/williamlong.xml? Cursor = 1, 1300794057949944903
Count. optional parameter. The maximum number of records returned each time (that is, the page size). The value is not greater than 200. The default value is 20.
Example: http://api.twitter.com/statuses/friends/bob.xml? & COUNT = 200
Statuses/followers
Return the authenticated user's subscriber, which contains the current message of each subscriber. Like friends, you only need to replace friends in the Friends address with followers. All other parameters, including parameters, do not need to be changed.
Access address:Http://api.twitter.com/statuses/followers.format
Supported formats(Format): XML, JSON
Parameter List:
Id. this parameter is optional. You need to obtain the UID or Weibo nickname of a fan.
Example: http://api.twitter.com/statuses/followers/12345.json or http://api.twitter.com/statuses/followers/bob.xml
User_id. optional parameter. UID to be obtained
Example: http://api.twitter.com/statuses/followers.xml? User_id = 1401881
Screen_name. optional parameter. Weibo nickname to be obtained
Example: http://api.twitter.com/statuses/followers.xml? Screen_name = 101010
Cursor. optional parameters. A single page can only contain a list of 100 fans. To get more fans, the cursor starts from-1 by default. You can increase or decrease the cursor to get more. If no next page exists, next_cursor returns 0.
Fan List Example: http://api.twitter.com/statuses/followers/barackobama.xml? Cursor =-1 Example: http://api.twitter.com/statuses/followers/barackobama.xml? Cursor = 1, 1300794057949944903
Count. optional parameter. The maximum number of records returned each time (that is, the page size). The value is not greater than 200. The default value is 20.
Example: http://api.twitter.com/statuses/followers/bob.xml? & COUNT = 200
Private Message Operation Method
Direct_messages
Back to the user's message list
Access address:Http://api.twitter.com/direct_messages.format
Supported formats(Format): XML, JSON, RSS, Atom
Parameter List:
Since_id. optional parameter. Return a private message whose ID is greater than the value since_id (later than the since_id time.
Example: http://api.twitter.com/direct_messages.xml? Since_id = 1, 12345
Max_id. optional parameter. Return the private message with the id not greater than max_id (not later than max_id.
Example: http://api.twitter.com/direct_messages.xml? Max_id = 54321
Count. optional parameter. Maximum number of records returned each time (that is, the page size), not greater than 200.
Example: http://api.twitter.com/direct_messages.xml? Count = 200
Page. optional parameter. Page number of the returned result. Note: There are paging restrictions.
Example: http://api.twitter.com/direct_messages.xml? Page = 3
Direct_messages/sent
Back to the user's sent message list
Access address:Http://api.twitter.com/direct_messages/sent.format
Supported formats(Format): XML, JSON, RSS, Atom
Parameter List:
Since_id. optional parameter. Return a private message whose ID is greater than the value since_id (later than the since_id time.
Example: http://api.twitter.com/direct_messages.xml? Since_id = 1, 12345
Max_id. optional parameter. Return the private message with the id not greater than max_id (not later than max_id.
Example: http://api.twitter.com/direct_messages.xml? Max_id = 54321
Count. optional parameter. Maximum number of records returned each time (that is, the page size), not greater than 200.
Example: http://api.twitter.com/direct_messages.xml? Count = 200
Page. optional parameter. Page number of the returned result. Note: There are paging restrictions.
Direct_messages/New
Send an authenticated message to a specified user, which must contain the user and text parameters. The request must be submitted in post mode. If the message is successfully sent, the complete message must contain the user and text parameters, and must be submitted in post mode. If the message is successfully sent, a complete message is returned.
Access address: Http://api.twitter.com/direct_messages/new.format
Supported formats(Format): XML, JSON
Parameter List:
User: user_id or screen_name
Text: Required parameter. urlencode is required for the message content to be generated. The text size must be less than 300 Chinese Characters
Direct_messages/destroy
After a specified Message ID is used to delete a specified Directed Message, the authenticated user can only delete the message received as the receiver. You can use both the post and get methods.
Access address:Http://api.twitter.com/direct_messages/destroy/id.format
Supported formats(Format): XML, JSON
Parameter List:
Id. Required parameter. ID of the private key to be deleted.
Example: http://api.twitter.com/direct_messages/destroy/12345.json
Friend relationship Operation Method
Friendships/create
Creates a friend relationship between the authenticated user and the user specified by the specified ID parameter. when the operation is successful, the user information added as a friend is returned. If the operation fails, the status string of the failed user is returned.
Access address:Http://api.twitter.com/friendships/create/id.format
Supported formats(Format): XML, JSON
Parameter List:
One of the following parameters is required:
Id. Required parameter. UID or Weibo nickname to be followed
Example: http://api.twitter.com/friendships/create/12345.json or http://api.twitter.com/friendships/create/bob.xml
User_id. this parameter is required. The user UID to be followed is used to distinguish the user uid from the microblog nickname.
Example: http://api.twitter.com/friendships/create.xml? User_id = 1401881
Screen_name. A required parameter. The microblog nickname to be followed is mainly used to distinguish the UID of a user from that of a microblog.
Example: http://api.twitter.com/friendships/create.xml? Screen_name = 101010
Follow. optional parameter. Currently not supported.
Friendships/destroy
Used to cancel a friend relationship with a user with the specified ID. when the operation is successful, the user with the canceled friend relationship will be returned. If the operation fails, the user will return the failure information.
Access address: Http://api.twitter.com/friendships/destroy/id.format
Supported format: XML, JSON
Parameter List:
One of the following parameters is required:
Id. this parameter is required. The user UID or Weibo nickname to be removed
Example: http://api.twitter.com/friendships/destroy/12345.json or http://api.twitter.com/friendships/destroy/bob.xml
User_id. this parameter is required. The UID of the user to be removed is used to distinguish the UID from the nickname of Weibo.
Example: http://api.twitter.com/friendships/destroy.xml? User_id = 1401881
Screen_name. Required parameter. The nickname of the Weibo account to be canceled. It is mainly used to distinguish the UID of the user from the nickname of the Weibo account.
Example: http://api.twitter.com/friendships/destroy.xml? Screen_name = 101010
Friendships/exists
It is used to check whether the relationship between two users is a friend or a relationship between follow and be followed. Returns the result of a relationship that follows each other. For example, a follows B. B does not follow. The corresponding format data is returned, such as XML, <result> <afollowb> true </afollowb> <bfollowa> false </bfollowa> </result>
Access address:Http://api.twitter.com/friendships/exists.format
Supported formats:XML, JSON
Parameter List:
User_a. Required parameter. UID to be determined
User_ B. Required parameter. uid of the user to be determined
Friendships/show
Returns the details of the two user relationships.
Access address:Http://api.twitter.com/friendships/show.format
Supported formats:XML, JSON
Parameter List:
The following parameters are optional. If this parameter is not specified, the current user is used.
Source_id. Source user uid
Example: http://api.twitter.com/friendships/show.xml? Source_id = 10502
Source_screen_name. Source Weibo nickname
Example: http://api.twitter.com/friendships/show.xml? Source_screen_name = Bob
One of the following parameters must be selected:
Target_id. Destination user UID to be determined
Example: http://api.twitter.com/friendships/show.xml? Target_id = 10503
Target_screen_name. Target Weibo nickname to be determined
Example: http://api.twitter.com/friendships/show.xml? Target_screen_name = William Long
How to obtain a user list
Friends/IDS
Used to obtain the user ID of a friend of a specified user. That is, the ID of the person who follows
Access address: Http://api.twitter.com/friends/ids.format
Supported formats:XML, JSON
Parameter List:
Id. this parameter is optional. You need to obtain the UID or Weibo nickname of a friend.
Example: http://api.twitter.com/friends/ids/12345.xml or http://api.twitter.com/statuses/friends/bob.xml
User_id. optional parameter. UID to be obtained
Example: http://api.twitter.com/friends/ids.xml? User_id = 1401881
Screen_name. optional parameter. Weibo nickname to be obtained
Example: http://api.twitter.com/friends/ids.xml? Screen_name = 101010
Cursor. optional parameter. A single page can contain only 5000 IDs. To obtain more IDs, the cursor starts from-1 by default. You can add or remove cursor to obtain more follow lists.
Example: http://api.twitter.com/friends/ids.xml? Cursor =-1 Example: http://api.twitter.com/friends/ids.xml? Cursor = 1, 1300794057949944903
Count. optional parameter. The maximum number of records returned each time (that is, the page size). If the value is not greater than 5000, 500 is returned by default.
Example: http://api.twitter.com/friends/ids.xml? Count = 200
Followers/IDS
Used to obtain the user ID that the specified user is following.
Access address: Http://api.twitter.com/followers/ids.format
Supported formats:XML, JSON
Parameter List:
Id. this parameter is optional. You need to obtain the UID or Weibo nickname of a friend.
Example: http://api.twitter.com/followers/ids/12345.xml or http://api.twitter.com/statuses/friends/bob.xml
User_id. optional parameter, UID to be obtained
Example: http://api.twitter.com/followers/ids.xml? User_id = 1401881
Screen_name. optional parameter. Weibo nickname to be obtained
Example: http://api.twitter.com/followers/ids.xml? Screen_name = 101010
Cursor. optional parameter. A single page can contain only 5000 IDs. To obtain more IDs, the cursor starts from-1 by default. You can add or remove cursor to obtain more follow lists.
Example: http://api.twitter.com/followers/ids.xml? Cursor =-1
Example: http://api.twitter.com/followers/ids.xml? Cursor = 1, 1300794057949944903
Count. optional parameter. The maximum number of records returned each time (that is, the page size). If the value is not greater than 5000, 500 is returned by default.
Example: http://api.twitter.com/followers/ids.xml? Count = 200
User Account Method
Account/verify_credentials
If the user's identity authentication is successful, the HTTP status is 200; if not, the status and error message of 401 are returned. This method uses to determine whether the user identity is valid.
Access address:Http://api.twitter.com/account/verify_credentials.format
Supported formats:XML, JSON
Parameter List:
Account/update_profile
Customize Weibo page parameters. Only the parameter update items are modified.
Access address:Http://api.twitter.com/account/update_profile.format
Supported formats:XML, JSON
Parameter List:
There must be one or more of the following parameters, and the parameter value is a string. For further restrictions, see the following parameter descriptions.
Name. Nickname. optional parameter. No more than 20 Chinese Characters
Gender gender, optional parameter. M, male, F, female.
Optional parameter of province. See the province city code table.
City is an optional parameter. For more information, see the province city code table. 1000 is not limited.
Description. Optional. No more than 160 Chinese characters.
Add methods to favorites
Favorites
Return the latest 20 favorite status information of authorized users. You can also specify a user by ID or user name to query the latest 20 favorite status information.
Access address: Http://api.twitter.com/favorites.format
Supported formats:XML, JSON, RSS, Atom
Parameter List:
Page: optional parameter. Page number of the returned result. Note: There are paging restrictions.
Example: http://api.twitter.com/favorites/11075.xml? Page = 3
Favorites/create
Add a new status information to post and submit
Access address:
Http://api.twitter.com/favorites/create.format
Supported formats:XML, JSON
Parameter List:
ID is required. ID of the status information to be added to the favorites folder.
Favorites/destroy
Deletes a favorite state information from an authorized user.
Access address: Http://api.twitter.com/favorites/destroy/id.format
Supported formats:XML, JSON
Parameter List:
ID: ID of the status information authorized to the user's favorites.