postdata
Post Twitter data
Syntax
Description
posts Twitter data using web service query parameters. The Twitter REST API defines web service query parameters for each endpoint. For
valid parameters, see the Twitter REST API Endpoint Reference Documentation.d = postdata(c,baseurl,parameters)
specifies web service query parameters as one or more pairs of name-value
arguments.d = postdata(c,baseurl,QueryName1,QueryValue1,...,QueryNameN,QueryValueN)
Examples
Use a Twitter connection object to check Twitter account settings. The REST API endpoint POST
account/settings does not require any web service query
parameters.
Create a Twitter connection using your credentials. (The values in this example do not represent real Twitter credentials.)
consumerkey = 'abcdefghijklmnop123456789'; consumersecret = 'qrstuvwxyz123456789'; accesstoken = '123456789abcdefghijklmnop'; accesstokensecret = '123456789qrstuvwxyz'; c = twitter(consumerkey,consumersecret,accesstoken,accesstokensecret);
Check the Twitter connection. If the StatusCode property has the value
OK, the connection is successful.
c.StatusCode
ans =
OKSpecify the Twitter base URL.
baseurl = 'https://api.twitter.com/1.1/account/settings.json';
Retrieve account settings using the Twitter connection object and base URL.
d = postdata(c,baseurl)
d =
ResponseMessage with properties:
StatusLine: 'HTTP/1.1 200 OK'
StatusCode: OK
Header: [1×22 matlab.net.http.HeaderField]
Body: [1×1 matlab.net.http.MessageBody]
Completed: 0d is a matlab.net.http.ResponseMessage object. The
StatusCode property shows OK,
indicating a successful HTTP request.
Access account settings data. Display the structure
Data.
d.Body.Data
ans =
struct with fields:
protected: 0
screen_name: 'screenName'
always_use_https: 1
use_cookie_personalization: 0
sleep_time: [1×1 struct]
geo_enabled: 0
language: 'en'
discoverable_by_email: 0
discoverable_by_mobile_phone: 0
display_sensitive_media: 0
allow_contributor_request: 'none'
allow_dms_from: 'following'
allow_dm_groups_from: 'following'
translator_type: 'none'
(These values do not represent real Twitter data.)
You can post data using other REST API endpoints by substituting another
URL for the baseurl input argument.
Use a Twitter connection object to create a Twitter search. Specify the search term for the saved search using a structure.
Create a Twitter connection using your credentials. (The values in this example do not represent real Twitter credentials.)
consumerkey = 'abcdefghijklmnop123456789'; consumersecret = 'qrstuvwxyz123456789'; accesstoken = '123456789abcdefghijklmnop'; accesstokensecret = '123456789qrstuvwxyz'; c = twitter(consumerkey,consumersecret,accesstoken,accesstokensecret);
Check the Twitter connection. If the StatusCode property has the value
OK, the connection is successful.
c.StatusCode
ans =
OKSpecify the search term MathWorks as a field of the
structure parameters. Specify the Twitter base URL for the REST API POST endpoint POST
saved_searches/create.
parameters.query = 'MathWorks'; baseurl = 'https://api.twitter.com/1.1/saved_searches/create.json';
Create a saved search using the Twitter connection object, base URL, and structure
parameters.
d = postdata(c,baseurl,parameters)
d =
ResponseMessage with properties:
StatusLine: 'HTTP/1.1 200 OK'
StatusCode: OK
Header: [1×23 matlab.net.http.HeaderField]
Body: [1×1 matlab.net.http.MessageBody]
Completed: 0
d is a matlab.net.http.ResponseMessage object. The
StatusCode property shows OK,
indicating a successful HTTP request.
Access the saved search data.
d.Body.Data
ans =
struct with fields:
id: 8.6011e+17
id_str: '860112019273416704'
query: 'MathWorks'
name: 'MathWorks'
position: []
created_at: 'Thu May 04 12:41:00 +0000 2017'd.Body.Data is a structure that contains information
about the saved search in fields. For example, the field
query contains the search term
MathWorks as a character vector.
You can post data using other REST API endpoints by substituting another
URL for the baseurl input argument.
Use a Twitter connection object to create a Twitter search. Specify the search term for the saved search as a name-value argument.
Create a Twitter connection using your credentials. (The values in this example do not represent real Twitter credentials.)
consumerkey = 'abcdefghijklmnop123456789'; consumersecret = 'qrstuvwxyz123456789'; accesstoken = '123456789abcdefghijklmnop'; accesstokensecret = '123456789qrstuvwxyz'; c = twitter(consumerkey,consumersecret,accesstoken,accesstokensecret);
Check the Twitter connection. If the StatusCode property has the value
OK, the connection is successful.
c.StatusCode
ans =
OKSpecify the Twitter base URL for the REST API POST endpoint POST
saved_searches/create.
baseurl = 'https://api.twitter.com/1.1/saved_searches/create.json';
Create a saved search for the search term MathWorks
using the Twitter connection object, base URL, and name-value argument
query.
d = postdata(c,baseurl,'query','MathWorks')
d =
ResponseMessage with properties:
StatusLine: 'HTTP/1.1 200 OK'
StatusCode: OK
Header: [1×23 matlab.net.http.HeaderField]
Body: [1×1 matlab.net.http.MessageBody]
Completed: 0
d is a matlab.net.http.ResponseMessage object. The
StatusCode property shows OK,
indicating a successful HTTP request.
Access the saved search data.
d.Body.Data
ans =
struct with fields:
id: 8.6011e+17
id_str: '860112019273416704'
query: 'MathWorks'
name: 'MathWorks'
position: []
created_at: 'Thu May 04 12:41:00 +0000 2017'd.Body.Data is a structure that contains information
about the saved search in fields. For example, the field
query contains the search term
MathWorks as a character vector.
You can post data using other REST API endpoints by substituting another
URL for the baseurl input argument.
Input Arguments
Twitter connection, specified as a twitter
object.
Twitter base URL, specified as a character vector or string scalar. Use this URL to access the Twitter REST API endpoints.
Example: 'https://api.twitter.com/1.1/followers/list.json' specifies a GET
REST API endpoint.
Data Types: char | string
Web service query parameters, specified as a structure. Each parameter is specified as a field in the structure. Set the field to a specific value in the structure. For example, specify the number of items for the HTTP request:
parameters.count = 20;
The Twitter REST API defines web service query parameters that it accepts as part of an HTTP request. For valid parameters, see the Twitter REST API Endpoint Reference Documentation.
Data Types: struct
Web service query parameters, specified as one or more pairs of name-value arguments. A QueryName argument is a character vector or string scalar that specifies the name of a query parameter. A QueryValue argument is a character vector or string scalar that specifies the value of the query parameter.
The Twitter REST API defines web service query parameters that it accepts as part of an HTTP request. For valid parameters, see the Twitter REST API Endpoint Reference Documentation.
Example: 'count',20 specifies the number of items for the HTTP
request.
Data Types: char | string
Output Arguments
Twitter data, returned as a matlab.net.http.ResponseMessage object.
To retrieve Twitter data, access properties in d, for example:
data = d.Body.Data
data =
struct with fields:
statuses: {50×1 cell}
search_metadata: [1×1 struct]
Continue to access the nested structure data to retrieve Twitter data. For accessing nested structures, see Access Data in Nested Structures.
Limitations
Each Twitter REST POST API endpoint has its own limitations. For details, see the Twitter REST API Endpoint Reference Documentation.
Version History
Introduced in R2017b
See Also
Functions
Objects
External Websites
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)