获取oauth_access_token 接口文档
https://developer.twitter.com/en/docs/basics/authentication/api-reference/token
根据用户名称查询用户信息接口
认证请求工具
composer require j7mbo/twitter-api-php
逻辑代码
$settings = array(
'oauth_access_token' => "**************",
'oauth_access_token_secret' => "**************",
'consumer_key' => "**************",
'consumer_secret' => "**************"
);
$twitter = new TwitterAPIExchange($settings);
//更具用户名获取用户最新的推文信息 每次获取前10条
$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = '?screen_name='.$userName.'&count=10';
$requestMethod = 'GET';
$lists = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
$lists = json_decode($lists);
根据关键字搜索推文信息接口
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=你好&result_type=popular';
$requestMethod = 'GET'
根据推文id获取具体信息包含推文用户信息
$url = 'https://api.twitter.com/1.1/statuses/show.json';
$getfield = '?id=986517452896002048';
$requestMethod = 'GET';
更具用户名获取用户最新的推文信息
$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = '?screen_name=SaudiVision2030&count=6';
$requestMethod = 'GET';