search
Search for Tweets
Syntax
Description
searches Tweets for the termd
= search(c
,tweetquery
)tweetquery
。
searches Tweets using web service query parameters. The Twitter®REST API定义Web服务查询参数。有关有效参数,请参阅获取搜索/推文。d
= search(c
,tweetquery
,parameters
)
将Web服务查询参数指定为一对名称值参数。d
= search(c
,tweetquery
,queryname1,queryvalue1,...,querynamen,queryvaluen
)
Examples
Search for Tweets
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
d
is 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 thesearch
function. To retrieve other Twitter data, use theGetData
function.
使用结构搜索特定数量的推文
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 termMathWorks
in 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
d
is 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 thesearch
function. To retrieve other Twitter data, use theGetData
function.
使用名称值参数搜索特定数量的推文
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
d
is 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 thesearch
function. To retrieve other Twitter data, use theGetData
function.
Input Arguments
c
—Twitter connection
twitter
object
Twitter connection, specified as atwitter
目的。
tweetquery
—微博搜索词
character vector|string scalar
微博搜索词, specified as a character vector or string scalar.
Example:"MathWorks"
数据Types:char
|string
parameters
—Web service query parameters
结构体
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
queryname1,queryvalue1,...,querynamen,queryvaluen
—Web service query parameters
name-value pairs
Web service query parameters, specified as one or more pairs of name-value arguments. AQueryName
argument is a character vector or string scalar that specifies the name of a query parameter. AQueryValue
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获取搜索/推文。
Example:'数数',20
retrieves 20 Tweets.
数据Types:char
|string
Output Arguments
d
— Twitter data
matlab.net.http.ResponseMessage
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
See Also
Functions
Objects
Topics
External Websites
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
您还可以从以下列表中选择一个网站:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- AméricaLatina(Español)
- Canada(English)
- United States(English)
欧洲
- Belgium(English)
- 丹麦(English)
- Deutschland(德意志)
- España(Español)
- Finland(English)
- 法国(Français)
- 爱尔兰(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- 挪威(English)
- Österreich(德意志)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)