主要内容

search

Search for Tweets

Description

example

d= search(c,tweetquery)searches Tweets for the termtweetquery

example

d= search(c,tweetquery,parameters)searches Tweets using web service query parameters. The Twitter®REST API定义Web服务查询参数。有关有效参数,请参阅获取搜索/推文

example

d= search(c,tweetquery,queryname1,queryvalue1,...,querynamen,queryvaluen)将Web服务查询参数指定为一对名称值参数。

Examples

collapse all

Use a Twitter connection object to search for Tweets.

使用您的凭据创建Twitter连接。(此示例中的值不代表实际的Twitter凭据。)

consumerkey ='abcdefghijklmnop123456789';commuterSecret ='qrstuvwxyz123456789';accesstoken ='123456789abcdefghijklmnop';accesstokensecret ='123456789qrstuvwxyz';c = twitter(consumerkey,consumersecret,accesstoken,accesstokensecret);

检查Twitter连接。如果是StatusCode属性具有值好的, the connection is successful.

C.StatusCode
ans =确定

使用Twitter连接对象和搜索词搜索推文MathWorks

tweetquery ='MathWorks';d = search(c,tweetquery)
d =带有属性的响应信息:statusline:'http/1.1 200 ok'statuscode:ok标头:[1×25 matlab.net.http.headerfield]身体:[1×1 matlab.net.http.message.message]完成:0:0

dis amatlab.net.http.ResponseMessage目的。TheStatusCode属性显示好的, indicating a successful HTTP request.

Access MathWorks®Tweets. Display the 12th Tweet.

d.Body.Data.statuses{12}.text
ans = 'MATLAB Control Systems Examples https://t.co/g2P86srv33'

You can search for other Tweets using thesearchfunction. To retrieve other Twitter data, use theGetDatafunction.

Use a Twitter connection object to search for 20 Tweets. Specify the number of Tweets to retrieve as a structure.

使用您的凭据创建Twitter连接。(此示例中的值不代表实际的Twitter凭据。)

consumerkey ='abcdefghijklmnop123456789';commuterSecret ='qrstuvwxyz123456789';accesstoken ='123456789abcdefghijklmnop';accesstokensecret ='123456789qrstuvwxyz';c = twitter(consumerkey,consumersecret,accesstoken,accesstokensecret);

检查Twitter连接。如果是StatusCode属性具有值好的, the connection is successful.

C.StatusCode
ans =确定

Specify the search termMathWorksin the variabletweetquery。Specify 20 Tweets as a field in the structureparameters。Search for 20 Tweets using the Twitter connection object, search termtweetquery和结构parameters

tweetquery ='MathWorks';parameters.count = 20; d = search(c,tweetquery,parameters)
d =带有属性的响应信息:statusline:'http/1.1 200 ok'statuscode:ok标头:[1×25 matlab.net.http.headerfield]身体:[1×1 matlab.net.http.message.message]完成:0:0

dis amatlab.net.http.ResponseMessage目的。TheStatusCode属性显示好的, indicating a successful HTTP request.

Access MathWorks Tweets. Display the structure数据

d.Body.Data
ans = struct with fields: statuses: {20×1 cell} search_metadata: [1×1 struct]

The structure数据contains the fieldstatuses。该字段是结构的细胞阵列。Each structure in the cell array contains information about one Tweet®

Access all 20 Tweets.

D.Body.Data.Statuses {:}
ans = with fields:create_at:'apr 28 17:51:55 +0000 2017'id:1.2345e +17 id_str:'123456789111112131'文本:'本收集400多个MATLAB示例可以帮助您使用#Controlsystems,Kalman,Kalman,Kalman,过滤器,以及更多https://t.co/fwndxkla6l''截断:0实体:[1×1 struct] metadata:[1×1 struct]来源:'twitter for iPhone'in_reply_to_to_to_status_id:[] in_reply_to_status_id:[]:[] in_reply_to_user_id_str:[] in_reply_to_screen_name:[]用户:[1×1 struct] geo:[]坐标:[] plote:[] plote:[] contutors:[] retweeted_status:[] retweeted_status:[1×1 struct] is_quote_status:0 ret_quote_status:0 reteet_count:0 reteet_c__c_c_c_c_c_c:34 FARYS:34 FAR着:34 FALYS:34 FAR着:34 FARYS:34 FAR着:0最喜欢:0转发:0可能是_sentive:0 lang:'en'...

The fieldtext在每个结构中都包含一个推文的文本。

(These values do not represent real Twitter data.)

You can search for other Tweets using thesearchfunction. To retrieve other Twitter data, use theGetDatafunction.

Use a Twitter connection object to search for 20 Tweets. Specify the number of Tweets to retrieve as a name-value argument.

使用您的凭据创建Twitter连接。(此示例中的值不代表实际的Twitter凭据。)

consumerkey ='abcdefghijklmnop123456789';commuterSecret ='qrstuvwxyz123456789';accesstoken ='123456789abcdefghijklmnop';accesstokensecret ='123456789qrstuvwxyz';c = twitter(consumerkey,consumersecret,accesstoken,accesstokensecret);

检查Twitter连接。如果是StatusCode属性具有值好的, the connection is successful.

C.StatusCode
ans =确定

Search for 20 Tweets using the Twitter connection object, search termMathWorks和名称值参数count

tweetquery ='MathWorks';d = search(c,tweetquery,'数数',20)
d =带有属性的响应信息:statusline:'http/1.1 200 ok'statuscode:ok标头:[1×25 matlab.net.http.headerfield]身体:[1×1 matlab.net.http.message.message]完成:0:0

dis amatlab.net.http.ResponseMessage目的。TheStatusCode属性显示好的, indicating a successful HTTP request.

Access MathWorks Tweets. Display the structure数据

d.Body.Data
ans = struct with fields: statuses: {20×1 cell} search_metadata: [1×1 struct]

The structure数据contains the fieldstatuses。该字段是结构的细胞阵列。单元阵列中的每个结构都包含有关一条推文的信息。

Access all 20 Tweets.

D.Body.Data.Statuses {:}
ans = with fields:create_at:'apr 28 17:51:55 +0000 2017'id:1.2345e +17 id_str:'123456789111112131'文本:'本收集400多个MATLAB示例可以帮助您使用#Controlsystems,Kalman,Kalman,Kalman,过滤器,以及更多https://t.co/fwndxkla6l''截断:0实体:[1×1 struct] metadata:[1×1 struct]来源:'twitter for iPhone'in_reply_to_to_to_status_id:[] in_reply_to_status_id:[]:[] in_reply_to_user_id_str:[] in_reply_to_screen_name:[]用户:[1×1 struct] geo:[]坐标:[] plote:[] plote:[] contutors:[] retweeted_status:[] retweeted_status:[1×1 struct] is_quote_status:0 ret_quote_status:0 reteet_count:0 reteet_c__c_c_c_c_c_c:34 FARYS:34 FAR着:34 FALYS:34 FAR着:34 FARYS:34 FAR着:0最喜欢:0转发:0可能是_sentive:0 lang:'en'...

The fieldtext在每个结构中都包含一个推文的文本。

(These values do not represent real Twitter data.)

You can search for other Tweets using thesearchfunction. To retrieve other Twitter data, use theGetDatafunction.

Input Arguments

collapse all

Twitter connection, specified as atwitter目的。

微博搜索词, specified as a character vector or string scalar.

Example:"MathWorks"

数据Types:char|string

Web服务查询参数,指定为结构。每个参数指定为结构中的字段。将字段设置为结构中的特定值。例如,指定要检索的推文数量:

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获取搜索/推文

数据Types:struct

Web service query parameters, specified as one or more pairs of name-value arguments. AQueryNameargument is a character vector or string scalar that specifies the name of a query parameter. AQueryValueargument 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获取搜索/推文

Example:'数数',20retrieves 20 Tweets.

数据Types:char|string

Output Arguments

collapse all

Twitter data, returned as amatlab.net.http.ResponseMessage目的。

To retrieve Twitter data, access properties ind, 例如:

数据= d.Body.Data
数据= struct with fields: statuses: {50×1 cell} search_metadata: [1×1 struct]

Continue to access the nested structure数据检索Twitter数据。对于访问嵌套结构,请参阅Access Data in Nested Structures

限制

  • The Twitter REST API获取搜索/推文endpoint specifies that you can retrieve up to a maximum of 100 Tweets at a time.

  • The Twitter REST API获取搜索/推文endpoint specifies that you can retrieve up to 7 days of historical Tweets.

Version History

Introduced in R2017b